cSciFiChick
New Member
- Joined
- Jul 31, 2014
- Messages
- 42
So I have this Marco to copy from each tab onto a single tab. The problem is I need 48 rows from each tab copied over and it is only doing that for the last one.
Here are the results:
Here is my Macro:
Here are the results:
Sheet | Job No | Change Order No | Change Order Seq | Date | Owner CO No | Status |
501X5 - Test Sheet | 501X5 | 0 | 2 | 2 | 500 | 0 |
501X5 | 0 | 2 | 2 | 0 | 0 | |
PCO# 2 - CCO# Pending | 2 | 0 | 2 | 2 | 1 | 0 |
2 | 0 | 2 | 2 | 0 | 0 | |
PCO# 1 - CCO# Pending | 1 | 0 | 2 | 2 | 40 | 0 |
1 | 0 | 2 | 2 | 0 | 0 | |
4 | 0 | 0 | ||||
7 | 0 | 0 | ||||
8 | 0 | 0 | ||||
9 | 100 | 1 | ||||
11 | 0 | 0 | ||||
12 | 0 | 0 | ||||
Here is my Macro:
Sub CopyRangeFromMultiWorksheets2()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim CopyRng As Range
aRange = "C3"
bRange = "B8:B55"
cRange = "F8:F55"
dRange = "H8:H55"
eRange = "G8:G55"
lRow = 2
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Delete the sheet "RDBMergeSheet2" if it exist
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("RDBMergeSheet2").Delete
On Error GoTo 0
Application.DisplayAlerts = True
'Add a worksheet with the name "RDBMergeSheet2"
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "RDBMergeSheet2"
DestSh.Range("A1:L1").Value = Array("Sheet", "Job No", "Change Order No", "Change Order Seq", "Date", "Owner CO No", "Status", "Change to Contract", "Change to Cost", "Units", "Comments", "Description")
Range("Z1").Value = "Headers"
'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets
'Loop through all worksheets except the RDBMerge worksheet and the
'Information worksheet, you can ad more sheets to the array if you want.
If IsError(Application.Match(sh.Name, _
Array(DestSh.Name, "1 - Accubid Data", "2 - Quoted Materials", "Summary-Sheet", "Header", "Details", "PCO# Template - CCO# Pending", "FD#Template - PCO# Pending", "List"), 0)) Then
'Comment out the following line if you don't want to
'include worksheet names in the summary sheet
Cells(lRow, 1) = sh.Name
'If you commented out the previous line, make a change
'in the following line: change (lRow, 2) to (lRow, 1)
sh.Range(aRange).Copy
Cells(lRow, 2).PasteSpecial xlPasteValues
Cells(lRow, 3).FormulaR1C1 = "0"
sh.Range(bRange).Copy
Cells(lRow, 4).PasteSpecial xlPasteValues
Cells(lRow, 5).FormulaR1C1 = "=IF(AND(RC[2]=0,RC[-1]=4),5,IF(RC[2]=0,2,1))"
sh.Range(cRange).Copy
Cells(lRow, 6).PasteSpecial xlPasteValues
Cells(lRow, 7).FormulaR1C1 = "0"
lRow = lRow + 1
sh.Range(aRange).Copy
Cells(lRow, 2).PasteSpecial xlPasteValues
Cells(lRow, 3).FormulaR1C1 = "0"
sh.Range(bRange).Copy
Cells(lRow, 4).PasteSpecial xlPasteValues
Cells(lRow, 5).FormulaR1C1 = "=IF(AND(RC[2]=0,RC[-1]=4),5,IF(RC[2]=0,2,1))"
sh.Range(dRange).Copy
Cells(lRow, 6).PasteSpecial xlPasteValues
sh.Range(eRange).Copy
Cells(lRow, 7).PasteSpecial xlPasteValues
lRow = lRow + 1
End If
Next
ExitTheSub:
Application.GoTo DestSh.Cells(1)
'AutoFit the column width in the DestSh sheet
DestSh.Columns.AutoFit
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub