worksheets

Dummy Excel

Well-known Member
Joined
Sep 21, 2005
Messages
992
Hi All,
This is a little tricky to explain so bear with me here!

I have a spreadsheet which could have 1 or more sheets. All the sheets are in the exact same format as the sheets are templates.

Currently my macro goes to the first sheet copies the sheet to the summary page and then goes back and copies the data to my summary page although I cant get the macro to go to the second sheet. Any ideas?
My code is:
Code:
ChDir strPath
strExtension = Dir(strPath & "*.xlsx")

        Do While strExtension <> ""
            Set wbOpen = Workbooks.Open(strPath & strExtension)
         
            With wbOpen
                ActiveWorkbook.Sheets(1).Select
                StatusReport = ActiveWorkbook.Name
                ProjectSheet = ActiveSheet.Name
            
            'Copy worksheets
            wsc = Worksheets.Count
            For Each ws In Worksheets
                    ws.Copy after:=Workbooks("Flightplan.xlsx").Sheets(3)

                'Copy Project Name
                Windows(StatusReport).Activate
                If wsc = 1 Then
                    Range("C5").Select.UnMerge
                    Range("C5").Copy
                    Windows(Flightplan).Activate
                    Sheets("Lookup Table").Activate
                Else
                    ActiveSheet.Next.Select
                    Range("C5").Select.UnMerge
                    Range("C5").Copy
                    Windows(Flightplan).Activate
                    Sheets("Lookup Table").Activate
                End If
                For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
                If Range("A" & i + 1).Value = "" Then
                Range("A" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                Else
                If i = i Then
                Else
                Range("A1").End(xlDown).Offset(1, 0).Select
                Range("A" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                End If
                End If
                Next i
            
    
                Windows(StatusReport).Activate
    
                'Copy Owner
                Range("E6").Copy
                Windows(Flightplan).Activate
    
                For i = 1 To Range("B" & Rows.Count).End(xlUp).Row
                If Range("B" & i + 1).Value = "" Then
                Range("B" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                Else
                If i = i Then
                Else
                Range("B1").End(xlDown).Offset(1, 0).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                   :=False, Transpose:=False
                End If
                End If
                Next i

                Windows(StatusReport).Activate
    
                'Copy Comments
                Range("G5").UnMerge
                Range("G5").Copy
                Windows(Flightplan).Activate
                
                For i = 1 To Range("C" & Rows.Count).End(xlUp).Row
                If Range("C" & i + 1).Value = "" Then
                Range("C" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                Else
                If i = i Then
                Else
                Range("C1").End(xlDown).Offset(1, 0).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                End If
                End If
                Next i

                Windows(StatusReport).Activate
    
                'Copy Update
                Range("L8").UnMerge
                Range("L8").Copy
                Windows(Flightplan).Activate
    
                For i = 1 To Range("D" & Rows.Count).End(xlUp).Row
                If Range("D" & i + 1).Value = "" Then
                Range("D" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                Else
                If i = i Then
                Else
                Range("D1").End(xlDown).Offset(1, 0).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                End If
                End If
                Next i

                Windows(StatusReport).Activate
    
                'Copy Overall Status
                Range("L5").Copy
                Windows(Flightplan).Activate
    
                For i = 1 To Range("E" & Rows.Count).End(xlUp).Row
                If Range("E" & i + 1).Value = "" Then
                Range("E" & i + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                Else
                If i = i Then
                Else
                Range("E1").End(xlDown).Offset(1, 0).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                    :=False, Transpose:=False
                End If
                End If
                Next i

                Windows(StatusReport).Activate
            
            Next ws
        End With
                
                Application.DisplayAlerts = False
                ActiveWorkbook.Close
                Application.DisplayAlerts = True
          
            strExtension = Dir
        Loop
All help is greatly appreciated
Sam
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,271
I think one problem might be the use of With wbOpen. Here's a partial example on how you should use it...

Code:
            With wbOpen
                '.Sheets(1).Select
                StatusReport = [COLOR="Red"].[/COLOR]Name
                ProjectSheet = [COLOR="Red"].Sheets(1)[/COLOR].Name
            
            'Copy worksheets
            wsc = [COLOR="Red"].[/COLOR]Worksheets.Count
            For Each ws In [COLOR="Red"].[/COLOR]Worksheets
                    ws.Copy after:=Workbooks("Flightplan.xlsx").Sheets(3)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,816
Messages
5,513,554
Members
408,957
Latest member
Jcoverick

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top