+ Reply to Thread
Results 1 to 10 of 10

How to use "if" logic in a macro

  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Cadillac, MI
    MS-Off Ver
    Excel 2003
    Posts
    81

    How to use "if" logic in a macro

    I would like to include some language in a macro that is similar to an "if" statement

    I'm using two sheets in the workbook. I already have the macro accomplishing some functions, but I also want the macro to do:

    at this point in the macro, the active cell is in Sheet2, cell B4
    if Sheet1, cell A50, is not blank; then =Sheet1!A50. So if cell B4 does get this formula, move on to the next command within the macro.
    however if Sheet1, cell A50, is blank; do not enter a formula into B4 and move on to the next command within the macro.

    thank you

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to use "if" logic in a macro

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: How to use "if" logic in a macro

    or more "complicated":
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to use "if" logic in a macro

    Hello tdf2437,

    You could consider this approach as well;

    Please Login or Register  to view this content.
    Here we are using the Sheet index Number instead of the Sheet Name, because if the Sheet Name is Changed the Code will fail.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Registered User
    Join Date
    01-13-2010
    Location
    Cadillac, MI
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: How to use "if" logic in a macro

    thank you to all who responded, I appreciate the help very much

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to use "if" logic in a macro

    You are welcome tdf2437,

    Glad we could help!

    Regards.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to use "if" logic in a macro

    Hello tdf2437,

    Thank for adding to my Reputation, I really appreciate it.

    Regards.

  8. #8
    Registered User
    Join Date
    01-13-2010
    Location
    Cadillac, MI
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: How to use "if" logic in a macro

    I would like to add a second question that ties directly with mehmetcik's response to my question:

    The macro is using all of the same logic as originally written, but instead of using =sheets("Sheet1").range("A58").value
    how would I would go about in having this actual formula post in B4 =a1+a2+a3

    Thank you

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to use "if" logic in a macro

    Select the developer tab

    Select Record Macro, remember the macro name.

    Type =a1+a2+a3 into cell B4

    Select Stop Recorder


    Select macros, select your macro and then click on edit.

    You should see something like:

    Please Login or Register  to view this content.

    This can be edited to:

    Please Login or Register  to view this content.

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: How to use "if" logic in a macro

    Hello tdf2437,

    Is this what you want?

    Please Login or Register  to view this content.
    Please see attached sample Workbook.

    Regards.
    Attached Files Attached Files
    Last edited by Winon; 11-16-2017 at 01:02 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. [SOLVED] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  3. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  4. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  5. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  6. Defining logic "Yes" or "No" , based on multiple conditions
    By pyol17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2012, 02:41 AM
  7. How can i copy value from "HTMLText"(EMBED("Forms.HTML:Text","")),using Macro
    By andrewyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2010, 12:47 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1