Need help editing a macro

Z

ZBelden

This macro was coded from here on this site (thanks for everyones help) and
it basically takes all the information from every worksheet in the workbook
and compiles it into one long list of data.

Sub UpdateMaster()
Dim ws As Worksheet 'Utility worksheet variable
Dim Dest As Range 'The cell in Col B of Master sht in which to paste
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then
Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(2,
-1)).Resize(, 13).ClearContents
End If
Set Dest = Range("B2")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master" Then
Dest.Offset(, -1).Value = ws.Name
With ws
.Range("A2", .Range("A" &
Rows.Count).End(xlUp)).Resize(, 12).Copy Dest
Set Dest = Range("B" & Rows.Count).End(xlUp).Offset(2)
End With
End If
Next ws
End Sub

My question is, how do I get it to ignore the first worksheet in the
workbook? Is there some command I can give to do this in the code? Any help
is appretiated.. If this is too vague I'll try and make my question more
specific
 
P

PCLIVE

I'm sure there are other ways, but I would do it this way.

Sub UpdateMaster()
Dim ws As Worksheet 'Utility worksheet variable
Dim Dest As Range 'The cell in Col B of Master sht in which to paste
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then
Range("A2", Range("B" &
Rows.Count).End(xlUp).Offset(2, -1)).Resize(, 13).ClearContents
End If
Set Dest = Range("B2")

For sh = 2 To Worksheets.Count

'For Each ws In ActiveWorkbook.Worksheets
If Sheets(sh).Name <> "Master" Then
Dest.Offset(, -1).Value = sheets(sh).Name
With Sheets(sh)
.Range("A2", .Range("A" &
Rows.Count).End(xlUp)).Resize(, 12).Copy Dest
Set Dest = Range("B" &
Rows.Count).End(xlUp).Offset(2)
End With
End If
Next sh
End Sub

Note: I've remarked statements with "ws" or changed the reference to
"Sheets(sh)".
HTH,
Paul
 
M

Mike H

or name the other sheet to exclude

If ws.Name <> "Master" and ws.name <> "Whatever" Then

Mike
 
Z

ZBelden

Worked like a charm, thanks guys.

PCLIVE said:
I'm sure there are other ways, but I would do it this way.

Sub UpdateMaster()
Dim ws As Worksheet 'Utility worksheet variable
Dim Dest As Range 'The cell in Col B of Master sht in which to paste
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then
Range("A2", Range("B" &
Rows.Count).End(xlUp).Offset(2, -1)).Resize(, 13).ClearContents
End If
Set Dest = Range("B2")

For sh = 2 To Worksheets.Count

'For Each ws In ActiveWorkbook.Worksheets
If Sheets(sh).Name <> "Master" Then
Dest.Offset(, -1).Value = sheets(sh).Name
With Sheets(sh)
.Range("A2", .Range("A" &
Rows.Count).End(xlUp)).Resize(, 12).Copy Dest
Set Dest = Range("B" &
Rows.Count).End(xlUp).Offset(2)
End With
End If
Next sh
End Sub

Note: I've remarked statements with "ws" or changed the reference to
"Sheets(sh)".
HTH,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top