Convert Column Formula into VBA codes

T

tqm1

Reference:
http://groups.google.com/group/micro... 616e111e2f166
http://www.excelforum.com/showthread.php?t=606282

Dear Experts

Columns E has folloiwng formula


Code
-------------------

=IF(AND($A2>=$C$2,$A2<=$D$2),IF(COUNTIF($B$2:$B2,$B2)=1,$B2,""),"")

-------------------


This works fine, But I want to fill Coulmn E with VBA codes.
To do this, I wrote this formula but it show error
Please help


Code
-------------------

Sub Command1_Click()
Dim iRow As Long, Lastr As Long
With Sheets("sheet1")
Lastr = .Range("A" & .Rows.Count).End(xlUp).Row
For iRow = 2 To Lastr
.Cells(iRow, "E").Value = "=IF(AND($A3>=$C$2,$A3<=$D$2),IF(COUNTIF($B$2:$B3,$B3)=1,$B3,""),"")"
Next iRow
End With
End Sub

-------------------


column A has Dates as 01-07-2007,02-07-07
Column B has cash as 10,20,30,40
C1 has criteria1 date
D1 has criteria2 date
column E has unique value

+-------------------------------------------------------------------
|Filename: Formula to VBA.zip
|Download: http://www.excelbanter.com/attachment.php?attachmentid=96
+-------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top