Consulting

Results 1 to 4 of 4

Thread: If...Then...Else - Help!

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Posts
    20
    Location

    If...Then...Else - Help!

    I am writing a bit of code that uses different subroutines.

    I only want one of the subroutines to execute if a given criteria is met, in my case, if cell is empty.

    The code I have so far is below, but it's not working for me:

    [VBA]Sub ReloadAdditionalIncome()

    Sheets("Reload Data").Select
    If Range("A4") = "" Then Exit Sub


    'reload additional income data
    Sheets("Reload Data").Select
    Range("A4:Y13").Copy
    Sheets("USER INPUTS - Additional Income").Select
    Range("F16").PasteSpecial Paste:=xlPasteValues
    Sheets("USER INPUTS - Additional Income").Select
    Range("F16").Select

    end sub
    [/VBA]

    I've tried the coding [VBA]if range("A4") = "" then go to NextSubRoutine[/VBA] but this doesn't seem to be helping either.

    This is the final stumbling block for this job so any help would be greatly appreciated.

    Thanks

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    [VBA]
    If range("A4").value = "" Then go To NextSubRoutine
    [/VBA]

    You may need to .value at the end to check it.

  3. #3
    VBAX Regular
    Joined
    Nov 2006
    Posts
    16
    Location
    [vba]
    If Range("A4").Value = "" Then GoTo NextSubRoutine

    [/vba]

    ska

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think you would be better with logic along the lines of

    [vba]

    Sub Overall()

    ReloadAdditionalIncome
    NextSubroutine
    End Sub

    Sub ReloadAdditionalIncome()

    Sheets("Reload Data").Select

    If Range("A4") = "" Then Exit Sub

    'reload additional income data
    Sheets("Reload Data").Select
    Range("A4:Y13").Copy
    Sheets("USER INPUTS - Additional Income").Select
    Range("F16").PasteSpecial Paste:=xlPasteValues
    Sheets("USER INPUTS - Additional Income").Select
    Range("F16").Select

    End Sub

    Sub NextSubroutine()

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •