Consulting

Results 1 to 3 of 3

Thread: Solved: VBA for "IF" function

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    15
    Location

    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

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    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
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Regular
    Joined
    Apr 2009
    Posts
    15
    Location
    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
  •