ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Convert Column Formula into VBA codes (https://www.excelbanter.com/excel-discussion-misc-queries/149188-convert-column-formula-into-vba-codes.html)

tqm1

Convert Column Formula into VBA codes
 
1 Attachment(s)
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 values


All times are GMT +1. The time now is 06:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com