-
Solved: VBA for "IF" function
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
-
I am assuming that your first row contains row header:
[VBA]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" & LastRow)
If cell.value = "" Then
cell.Value = Sheet1.Range("C" & x).Value
End If
x = x + 1
Next
MsgBox "Date adjustments have been completed."[/VBA]
HTH
*code is untested and written from memory
-
Brilliant, that works a treat thanks for the quick response.
Have a great day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules