michellebenton2012
New Member
- Joined
- Aug 31, 2013
- Messages
- 4
Hi,
I am working on a marco and have a few kinks I need to work through. So far I am able to copy all the sheets I want to into one sheet. I am not trying to copy only certain columns from those sheets as well as apply an autofilter to copy only to rows that are "Active".
here is my code:
Private Sub Worksheet_Activate()
'Consolidates data from the range B6:Q2215 for every tab except the one it's part of.
Dim wrkSheet As Worksheet
Dim rngCopy As Range
Dim lngPasteRow As Long
Dim strConsTab As String
strConsTab = ActiveSheet.Name 'Consolidation sheet tab name based on active tab.
If Sheets(strConsTab).Cells(Rows.Count, "B").End(xlUp).Row >= 2 Then
If MsgBox("Do you want to clear the existing consolidated data in """ & strConsTab & """", vbQuestion + vbYesNo, "Data Consolidation Editor") = vbYes Then
Sheets(strConsTab).Range("B6:Q" & Cells(Rows.Count, "B").End(xlUp).Row).ClearContents
End If
End If
Application.ScreenUpdating = False
For Each wrkSheet In ActiveWorkbook.Worksheets
If wrkSheet.Name <> strConsTab And wrkSheet.Name <> "Inactive" And wrkSheet.Name <> "Head Count" And wrkSheet.Name <> "Colombia" And wrkSheet.Name <> "China JV" And wrkSheet.Name <> "Sustain" And wrkSheet.Name <> "AMS" Then
Set rngCopy = wrkSheet.Range("B:B, E:E, G:J,L:L, N:N, Q:Q, R:R")
lngPasteRow = Sheets(strConsTab).Cells(Rows.Count, "B").End(xlUp).Row + 1
rngCopy.Copy Sheets(strConsTab).Range("B" & lngPasteRow)
Application.CutCopyMode = False
End If
Next
End Sub
The red area above designated the columns I want to copy over. It says the copy are and paste area are not the same size and highlights this code:rngCopy.Copy Sheets(strConsTab).Range("B" & lngPasteRow)
I am still not even sure how to use the auto filters to filter on column 8 criteria = "A"
Please help thanks!
I am working on a marco and have a few kinks I need to work through. So far I am able to copy all the sheets I want to into one sheet. I am not trying to copy only certain columns from those sheets as well as apply an autofilter to copy only to rows that are "Active".
here is my code:
Private Sub Worksheet_Activate()
'Consolidates data from the range B6:Q2215 for every tab except the one it's part of.
Dim wrkSheet As Worksheet
Dim rngCopy As Range
Dim lngPasteRow As Long
Dim strConsTab As String
strConsTab = ActiveSheet.Name 'Consolidation sheet tab name based on active tab.
If Sheets(strConsTab).Cells(Rows.Count, "B").End(xlUp).Row >= 2 Then
If MsgBox("Do you want to clear the existing consolidated data in """ & strConsTab & """", vbQuestion + vbYesNo, "Data Consolidation Editor") = vbYes Then
Sheets(strConsTab).Range("B6:Q" & Cells(Rows.Count, "B").End(xlUp).Row).ClearContents
End If
End If
Application.ScreenUpdating = False
For Each wrkSheet In ActiveWorkbook.Worksheets
If wrkSheet.Name <> strConsTab And wrkSheet.Name <> "Inactive" And wrkSheet.Name <> "Head Count" And wrkSheet.Name <> "Colombia" And wrkSheet.Name <> "China JV" And wrkSheet.Name <> "Sustain" And wrkSheet.Name <> "AMS" Then
Set rngCopy = wrkSheet.Range("B:B, E:E, G:J,L:L, N:N, Q:Q, R:R")
lngPasteRow = Sheets(strConsTab).Cells(Rows.Count, "B").End(xlUp).Row + 1
rngCopy.Copy Sheets(strConsTab).Range("B" & lngPasteRow)
Application.CutCopyMode = False
End If
Next
End Sub
The red area above designated the columns I want to copy over. It says the copy are and paste area are not the same size and highlights this code:rngCopy.Copy Sheets(strConsTab).Range("B" & lngPasteRow)
I am still not even sure how to use the auto filters to filter on column 8 criteria = "A"
Please help thanks!