Consulting

Results 1 to 6 of 6

Thread: convert excel if condition to vba code

  1. #1

    convert excel if condition to vba code

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

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

    but, < "d"?
    ____________________________________________
    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

  3. #3
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Okay, so what is wrong with your original code then?
    ____________________________________________
    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

  5. #5
    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

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Your code increments the line number for each row. Run it and then go look at B3, B4 and so on.
    ____________________________________________
    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
  •