PDA

View Full Version : convert excel if condition to vba code



vdeen
01-23-2008, 04:16 PM
hi,

this following algorithm is in my excel, i would like have a VBA code for the following.

Range("B3:b5000").formula = "=IF($E3<""d"",""ANZSIC Description"",""Primary Activities"")"


thanks

Bob Phillips
01-23-2008, 04:39 PM
If Range("E3").Value < "d" Then
Range("B3:B5000").Value = "ANZSIC Description"
Else
Range("B3:B5000").Value = "Primary Activities"
End If


but, < "d"?

vdeen
01-23-2008, 04:46 PM
thank you. but in the code the range is my concern. the ways it should be is
for cell b3 it should look at e3

for cell b4 it should look at e4
and so on

please help

If Range("E3").Value < "d" Then
Range("B3:B5000").Value = "ANZSIC Description"
Else
Range("B3:B5000").Value = "Primary Activities"
End If

Bob Phillips
01-23-2008, 05:14 PM
Okay, so what is wrong with your original code then?

vdeen
01-23-2008, 05:18 PM
hi,

the original algorithm has $ sign which means it should look at the next cells in column b & E

in simple terms for B3 it should look at E3
and B4 to look at E4

the excel algorith does that with the $ sign, how can we do that in VBA code

Bob Phillips
01-23-2008, 05:22 PM
Your code increments the line number for each row. Run it and then go look at B3, B4 and so on.