Results 1 to 8 of 8

For Loop Issue

Threaded View

pr4t3ek For Loop Issue 11-12-2008, 09:05 AM
duckboy1981 Hi, You havent actually... 11-12-2008, 09:41 AM
pr4t3ek Sorry, What i want to know... 11-12-2008, 09:49 AM
romperstomper Where is the code located -... 11-12-2008, 10:03 AM
pr4t3ek Hi, Yes the sheet name is an... 11-12-2008, 10:05 AM
romperstomper It's probably due to this... 11-12-2008, 10:16 AM
duckboy1981 Agreed - you need this line... 11-12-2008, 10:27 AM
pr4t3ek hmmm that sure is... 11-12-2008, 10:40 AM
  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    For Loop Issue

    I have the following code:

        'go back to crmtasks and copy second page
        Windows("CRMTasks" & Format(Date, "ddmmyyyy") & ".xls").Activate
      For i = 2 To 20
        If WksExists("DataImport" & i) Then
        Sheets("DataImport" & i).Select
        Rows("1:1").Select
        Application.CutCopyMode = False
        Selection.AutoFilter Field:=1, Criteria1:="10000007"
        Cells.Select
        Selection.Copy
        
        'go to new workbook and paste
        Windows("SOSCRMTasks" & Format(Date, "ddmmyyyy") & ".xls").Activate
        If Not WksExists("Sheet" & i) Then
        Sheets.Add.Name = ("Sheet" & i)
     End If
        Sheets("Sheet" & i).Select
        ActiveSheet.Paste
            Rows("1:1").Select
        Application.Run "PERSONAL.XLS!XcessSpaces"
           If Dir(SOSPath) <> "" Then
       Call ExporttoAccessSOS
       End If
    End If
     Next i
    The WksExists Function:

    Function WksExists(wksName As String) As Boolean
        On Error Resume Next
        WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
    End Function
    The code works fine but it only works for Sheet1 & DataImport2 but not DataImport3.

    Hence why the loop does not copy the relavent data from the DataImport3 page onto a "Sheet3" in SOSCRMTasks.xls

    I am working on an old file at the moment, but in reality the file is more than four pages now . e.g Sheet1, DataImport2, DataImport3, DataImport4 ....

    thank You
    Last edited by pr4t3ek; 11-12-2008 at 10:39 AM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

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