+ Reply to Thread
Results 1 to 5 of 5

Find record stuck at "Next i"

  1. #1
    Registered User
    Join Date
    10-18-2013
    Location
    Georgetown, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Find record stuck at "Next i"

    Hai, I new to VBA and would like help trying to figure out how to write this code.
    It stuck at "Next i" what code should i use. Did i missing a step or using a wrong code.
    Thank in advance.

    Sub finddata()

    '1. declare variables
    '2. clear old search results
    '3. find records that match criteria and paste them

    Dim Source As String
    Dim Month As String
    Dim Year As String
    Dim finalrow As Integer
    Dim i As Integer 'row counter

    Sheets("Master").Range("AN6:AX300").ClearContents

    Source = Sheets("Master").Range("AN2").Value
    Month = Sheets("Master").Range("AP2").Value
    Year = Sheets("Master").Range("AQ2").Value
    finalrow = Sheets("Master").Range("B10000").End(xlUp).Row

    For i = 2 To finalrow
    If Cells(i, 2) = Source Then
    If Cells(i, 5) = Month Then
    If Cells(i, 6) = Year Then
    Range(Cells(i, 2), Cells(i, 12)).Copy
    Range("AN100").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
    End If
    Next i
    Range("AN2").Select
    Range("AP2").Select
    Range("AQ2").Select

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Find record stuck at "Next i"

    Try:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Find record stuck at "Next i"

    Please use code tags to post code in the future.

    Try changing the loop to:

    Please Login or Register  to view this content.
    You were missing 2 End If's, might be the problem.

  4. #4
    Registered User
    Join Date
    10-18-2013
    Location
    Georgetown, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Find record stuck at "Next i"

    Thanks Fredlo, it work. Problem solve. Thank also to millz for the reason why it not functioning.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find record stuck at "Next i"

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    AND

    Your post does not comply with Rule 3 of our Forum
    RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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] 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
  2. Replies: 3
    Last Post: 04-14-2013, 11:53 PM
  3. [SOLVED] Find "LOGGED IN" person and record their "LOG OUT" time next to them
    By TruBeast in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 03-07-2013, 05:46 PM
  4. [SOLVED] Find multiple "text" criteria and return as ""Yes" in Matrix
    By bertrand82 in forum Excel General
    Replies: 11
    Last Post: 04-30-2012, 09:20 AM
  5. Replies: 5
    Last Post: 06-26-2006, 09:23 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