+ Reply to Thread
Results 1 to 7 of 7

Loop until won't stop!?

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2007
    Posts
    47
    the value of x1up when it finishes is -4162 but i only have 2 row in this test example? should it not be 65536 less 2?

    i have tried clearing the cells below my data but it didnt help?

    thanks

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    The instruction
    Cells(Rows.Count, 2).End(xlUp).Row 'the 2 means column 2
    do the same thing than go to max row of column 2 (for example B65536) then press 'End' and 'Up' to go to the last row of column 2.

    To fix your problem try to do so:
    lastRow = Sheets("export").Cells(Rows.Count, 2).End(xlUp).Row 'the 2 means column 2
    
    For i = 1 To lastRow
       'your code
    next i
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    06-19-2007
    Posts
    47
    thanks for the help.

    i sorted it buy just using

    n=1

    my coded

    n=n+1
    end sub

    thanks for all the help its mcuh appreciated

    any thoughts on the deleting sheets questions? (see post)

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Why do you have a For loop inside a Do Loop?

    Instead of seleting sheets & ranges all the time you could use something like this code


    Macro1()
       Dim lLR As Long
       Dim lRow As Long
       Dim wsE As Worksheet
       
       Dim sSheetName As String
       
       Application.ScreenUpdating = False
       
       Set wsE = Sheets("export")
       lLR = wsE.Cells(Rows.Count, "a").End(xlUp).Row
       For lRow = 2 To lLR Step 1
          sSheetName = wsE.Cells(lRow, "ar").Value
          Sheets("Template").Copy After:=Sheets(1)
          Sheets("Template (2)").Name = sSheetName
          Sheets(sSheetName).Select
          
          wsE.Cells(lRow, "a").Copy
          Range("E2:AA2").Select
          ActiveSheet.Paste
    
          wsE.Range("b" & lRow & ":c" & lRow).Copy
          Range("h10:h11").Select
          ActiveSheet.Paste
    
          wsE.Cells(lRow, "d").Copy
          Range("E6").Select
          ActiveSheet.Paste
        
          wsE.Cells(lRow, "at").Copy
          Range("e38").Select
          ActiveSheet.Paste
       Next lRow
       Set wsE = Nothing
    End Sub
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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