+ Reply to Thread
Results 1 to 6 of 6

VBA IF statement

  1. #1
    Registered User
    Join Date
    03-09-2011
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    VBA IF statement

    Hello, I am attempting to insert an IF statement into an existing macro, such that if the last column in a specific worksheet is column G, then stop the routine. If not, then continue. I'm still a novice with VBA code and am missing something simple. Here is the code I am attempting to insert. Thank you for any help!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA IF statement

    Try
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA IF statement

    Hi there,

    Try this:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    03-09-2011
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA IF statement

    Hi Robert, I need the routine to be specific to column G, so I modified the code to =7. However, that did not work. I used <=7, and it worked the first time, but subsequent runs did not work. Here's some additional backgound ... the first part of the code copies values to "DATA COPY" worksheet. That data is summarized in another worksheet "Scorecard", and uses formulas to look up the data. The first time that data is copied to "DATA COPY", it will always copy to column G. Subsequent data will be copied to column H and so on. The first summary in "Scorecard" is also in column G, but the formulas already exist. The last section of the code copies the formulas to the next column (e.g., from column G to column H). What I am trying to avoid is copying the formulas the first time. Using =7 copies all the time, using <=7 never copies. Here's the full code. Any suggestions?

    Please Login or Register  to view this content.
    Last edited by itwas45and51; 01-18-2015 at 02:26 AM. Reason: corrected If statement

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA IF statement

    If the following doesn't work please attach a workbook (devoid of sensitive data) with notes of what you're trying to achieve:

    Please Login or Register  to view this content.
    Robert

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA IF statement

    If the following doesn't work please attach a workbook (devoid of sensitive data) with notes of what you're trying to achieve:

    Please Login or Register  to view this content.
    Robert

  7. #7
    Registered User
    Join Date
    03-09-2011
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA IF statement

    Added Exit Sub prior to End If and it worked wonderfully! Thank you for your help and patience!

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA IF statement

    You're welcome

    Thanks also for marking the thread as solved and for adding to my rep

+ 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. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  2. VBA Compile Error : line number or label or statement or end of statement
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2013, 06:41 PM
  3. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  4. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  5. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM

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