+ Reply to Thread
Results 1 to 12 of 12

If Statement inside For Next

  1. #1
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    If Statement inside For Next

    So here is what I have .... I'm trying to make sure the 2 cells equal each other. That tells me my previous code worked. Once it matches, then I need that value to be sent to the other Worksheet (Results). It's only copying the last data on the 4th sheet (Invoice 4). All help is greatly appreciated!

    Thanks!

    Please Login or Register  to view this content.
    By the way, lLR is the last row
    Please Login or Register  to view this content.
    Last edited by nkitchen31; 09-14-2021 at 11:08 PM.

  2. #2
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    This code assumes that the "1LR" last row and ".Range" ranges that do not have a sheet specified, are all referenced from the "Results" sheet.
    Please Login or Register  to view this content.
    Last edited by unit285; 09-15-2021 at 02:50 AM.

  3. #3
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: If Statement inside For Next

    well I think I'm trying to do the opposite...
    Take the values that are derived on Invoice 1 through 4 and put them on the Results worksheet.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: If Statement inside For Next

    the reason is the last 'lLR' value to be established in the first loop would be for 'sh' = 4, you have then gone on to apply this value to ws("Invoice 1") etc., etc., etc.,
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  5. #5
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    Would u be able to upload a copy of your workbook?

  6. #6
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    Try this. Hard to test because I have no idea what the datasets on your Invoices and Results Sheets look like.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: If Statement inside For Next

    OKay I have attached the WS.

    The way it is now is before the macro is run. All 4 invoices were copied over from PDF into the XLSM. When you click Run Macro, it'll condense the invoices.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    Try it now
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: If Statement inside For Next

    I went over and over and over your code ... I love it. Thank you so much. Makes sense!

    Original Code:
    Please Login or Register  to view this content.
    I'm trying to add LastRow H and LastRow J together ... am I close?
    Please Login or Register  to view this content.
    Last edited by nkitchen31; 09-15-2021 at 11:42 PM.

  10. #10
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    Assuming you want to add Reimbursements and Withholdings together in one number try replacing
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    04-09-2010
    Location
    Fort Myers, FL
    MS-Off Ver
    Excel for MAC
    Posts
    146

    Re: If Statement inside For Next

    As suspected, parentheses in the wrong spot. Thanks again!

  12. #12
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: If Statement inside For Next

    You're welcome! Thanks for the Rep!
    Last edited by unit285; 09-16-2021 at 08:52 AM.

+ 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. [SOLVED] IF Statement with Multi-Criteria Statement inside a Data Validation List
    By dharvey1978 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-31-2020, 09:10 PM
  2. Datediff inside if statement
    By ngenova in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2018, 12:44 PM
  3. Need help with a S Q L statement inside VBA
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-30-2018, 08:32 AM
  4. [SOLVED] Can You Put An IF Statement Inside a REPLACE Statement?
    By nevi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2014, 07:34 AM
  5. Using a VLOOKUP and IF statement inside an IF statement
    By Isis3 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-08-2011, 07:04 PM
  6. Using Next inside an IF statement
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2010, 10:27 AM
  7. If, then inside a for, next statement?
    By EnergyEngineer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-10-2007, 05:04 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