PDA

View Full Version : Solved: VBA for "IF" function



rhk001
04-21-2009, 01:23 PM
Hi Guys,

Can anyone help me with this question please. I have some two sets of dates, Start dates in Column C, Finish Dates in Column D. I want to loop through Column D and where it is blank, repalce the balnk with the value in column C. (The data gets imported into Excel so amount of data / rows can vary)



I have done this using the If function, bit would like to do it using VBA. The function is simply =IF(C2="",D2,C2)

Thanks:doh:

CreganTur
04-21-2009, 01:37 PM
I am assuming that your first row contains row header:

Dim cell As Range
Dim x As Integer
Dim LastRow As Long

LastRow = Sheet1.Range("A65536").End(xlUp).Row
x = 2

For Each Cell In Range("D2:D" & LastRow)
If cell.value = "" Then
cell.Value = Sheet1.Range("C" & x).Value
End If
x = x + 1
Next

MsgBox "Date adjustments have been completed."

HTH:thumb

*code is untested and written from memory

rhk001
04-21-2009, 01:47 PM
Brilliant, that works a treat thanks for the quick response.

Have a great day.