If Not [ISREF(Master!A1)] Then
Sheets.Add(, Sheets(Sheets.Count)).Name = "Master"
Else
Sheets("Master").UsedRange.EntireColumn.Delete
End If
Above checks if you have a sheet named "Master".
If not, it will add a worksheet to the end and name it "Master"
If there is a "Master" sheet, instead of deleting it and adding it again it will
delete all the used columns so you'll have a clean sheet again.
With Sheets("Sheet1")
.Range(.Cells(1, 1), .Cells(1, .UsedRange.Columns.Count)).Copy Sheets("Master").Range("A1")
.Range("G2:G" & .Cells(.Rows.Count, "G").End(xlUp).Row).Copy .Range("K2")
End With
Above copies the first row in Sheet1 to the first row in the "Master" sheet
It also copies from cell G2 to the last used cell in column G in Sheet1 to column K starting at K2
Sheets("Sheet3").Range("K2:K" & Sheets("Sheet3").Cells(Rows.Count, "K").End(xlUp).Row).ClearContents
Above part of the code clears column K, starting at K2, in Sheet3
For i = 1 To 3
With Sheets(i)
lr = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
lc = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
.Range(.Cells(1, 1), .Cells(lr, lc)).Copy Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Offset(1)
End With
Next i
This part of the code cycles through the first three sheets and copies cell A1 to the last used row and last
used column and paste it into the "Master" sheet at the first free (=empty) cell in Column A
It does this, as mentioned, for all three sheets
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master" Then ws.Delete
Next ws
Application.DisplayAlerts = True
This part deletes all sheets except a sheet called "Master"
The "DisplayAlerts" statement is to avoid getting the popup asking if it is OK to delete the sheet with data in it.
Re: Your Post #6
.Range(.Cells(1, 1), .Cells(1, .UsedRange.Columns.Count)).Copy Sheets("Master").Range("A1")
.Range("G2:G" & .Cells(.Rows.Count, "G").End(xlUp).Row).Copy .Range("K2")
These two lines need to be between "With" and "End With" because of the preceding periods (.)
VBA knows that anything starting with a period is a property or a method of the object following the With
http://www.java2s.com/Code/VBA-Excel...ingtheWith.htm
http://www.homeandlearn.org/with_end_with.html
http://www.quepublishing.com/article...21718&seqNum=5
Example:
If you are in any sheet but not Sheet1 and run the following
With Sheets("Sheet1")
'some code here
.Range("A1:A10").Interior.Color = vbRed '<----- has preceding period
End With
it will color that range in Sheet1 to red.
With Sheets("Sheet1")
'some code here
Range("A1:A10").Interior.Color = vbRed '<----- no preceding period
End With
this will color the range of the sheet you are in to red, not in Sheet1
Still waiting on answers for the questions in Post #9