Consulting

Results 1 to 10 of 10

Thread: If Statement Excel Macro

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location

    If Statement Excel Macro

    Through the use of an Excel macro If Statement, I want to be able to analyze the current cell position and depending on the cell position have the macro move the cursor. This is the statement that I wrote but does not seem to work. It skips to the end if and does not perform the command.


    If ActiveCell = "$A$2" Then
    'Application.Goto Reference:="R10C1"
    End If

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Bob,

    Try using A1 style references throughout your macro. You don't need Application.GoTo. You can move to a cell simply by selecting it.

    If ActiveCell.Address = "$A$2" Then
        Range("$A$10").Select
    End IF
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    Leith,

    Thank you so much. That worked great!

  4. #4
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Bob,

    You're welcome.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  5. #5
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    Leith,

    Can you tell me how to check for a blank cell. Sorry, this is my first attempt at Excel macros so I am a bit novus. Below is what I am trying but it is no working. Again it is skipping to the End If. Thank you

    If ActiveCell.Address = "" Then
    ActiveCell.FormulaR1C1 = "1"
    End If

  6. #6
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    Leith,

    I figured it out

    Set rRng = Sheet1.Range("A3")
    If IsEmpty(rRng.Value) Then

  7. #7
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Bob,

    Good work for a novice.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Yea, that's the best way to learn

    You can mark your question solved by using [Tread Tools] about your first post, and selection [Solved]
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Regular
    Joined
    May 2017
    Posts
    28
    Location
    Thanks everyone. This is a fantastic website. Paul I will mark as solved through thread tools but I not sure how to do that. Thanks

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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