Hello again! This forum helped me a few months ago with this macro to move data from one sheet ("Raw Data TY" & "Raw Data LY") to another ("Discount", "Group", Corporate", etc). The macro has been working well until I added the "Group" sheet.
What I need to happen is the data that is in the "Raw Data" sheets to be copy/pasted to the destination tab (Discount, Corporate, Group, etc) based on the value of column A. Everything is working correctly for the "Raw Data TY" sheet. However, the "Raw Data LY" sheet will not move Q,R,S,T,U,V over to the "Group" destination sheet - it only moves V. The same thing happens with "Comp" & W,X,Y,Z....it works correctly for the "TY" data, but not "LY".
<tbody>
</tbody>
Macro is below:
Sub CopyStuff()
Dim sh1 As Worksheet, sh2 As Worksheet, dsh As Worksheet, shAry As Variant, dAry As Variant, i As Long, j As Long
Set sh1 = Sheets("Raw Data TY")
Set sh2 = Sheets("Raw Data LY")
shAry = Array(sh1, sh2)
dAry = Array("A", "B", "C", "D", "E", "F", "G", "I", "Q", "R", "S", "T", "U", "V", "O", "W", "X", "Y", "Z")
For i = LBound(shAry) To UBound(shAry)
For j = LBound(dAry) To UBound(dAry)
shAry(i).UsedRange.Offset(1).AutoFilter 1, dAry(j)
Select Case dAry(j)
Case "A"
Set dsh = Sheets("Leisure")
Case "B"
Set dsh = Sheets("Package")
Case "C"
Set dsh = Sheets("Consortia")
Case "D"
Set dsh = Sheets("Discount")
Case "E"
Set dsh = Sheets("FIT")
Case "F"
Set dsh = Sheets("Corporate")
Case "G"
Set dsh = Sheets("Govt")
Case "I"
Set dsh = Sheets("Echannel-OTA")
Case "Q" To "V"
Set dsh = Sheets("Group")
Case "W" To "Z"
Set dsh = Sheets("Comp")
Case "O"
Set dsh = Sheets("owner")
End Select
If shAry(i) Is sh1 Then
If dsh.Range("B44") = "" Then
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh.Range("B44")
Else
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh. _
Cells(Rows.Count, 2).End(xlUp)(2)
End If
Else
If dsh.Range("R44") = "" Then
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh.Range("R44")
Else
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh. _
Cells(Rows.Count, 11).End(xlUp)(2)
End If
End If
shAry(i).AutoFilterMode = False
Next
Next
End Sub
Appreciate the help!
~Vanessa
What I need to happen is the data that is in the "Raw Data" sheets to be copy/pasted to the destination tab (Discount, Corporate, Group, etc) based on the value of column A. Everything is working correctly for the "Raw Data TY" sheet. However, the "Raw Data LY" sheet will not move Q,R,S,T,U,V over to the "Group" destination sheet - it only moves V. The same thing happens with "Comp" & W,X,Y,Z....it works correctly for the "TY" data, but not "LY".
A | B | C | D | E | F | G | |
1 | D |
<tbody> </tbody> | D20ABR | 7/30 - 8/6/17 | 10G26Y | 204.44 | |
2 | Q | 11A8D3 | SGR239 | 7/28 - 7/29/17 | 1181MN | 239 | |
3 | T | 1186RI | SGR229 | 7/6 - 7/10/17 | 1186GP | 229 | |
4 | V | 11A465 | SGR215 | 7/11 - 7/14/16 | 1104YS | 215 |
<tbody>
</tbody>
Macro is below:
Sub CopyStuff()
Dim sh1 As Worksheet, sh2 As Worksheet, dsh As Worksheet, shAry As Variant, dAry As Variant, i As Long, j As Long
Set sh1 = Sheets("Raw Data TY")
Set sh2 = Sheets("Raw Data LY")
shAry = Array(sh1, sh2)
dAry = Array("A", "B", "C", "D", "E", "F", "G", "I", "Q", "R", "S", "T", "U", "V", "O", "W", "X", "Y", "Z")
For i = LBound(shAry) To UBound(shAry)
For j = LBound(dAry) To UBound(dAry)
shAry(i).UsedRange.Offset(1).AutoFilter 1, dAry(j)
Select Case dAry(j)
Case "A"
Set dsh = Sheets("Leisure")
Case "B"
Set dsh = Sheets("Package")
Case "C"
Set dsh = Sheets("Consortia")
Case "D"
Set dsh = Sheets("Discount")
Case "E"
Set dsh = Sheets("FIT")
Case "F"
Set dsh = Sheets("Corporate")
Case "G"
Set dsh = Sheets("Govt")
Case "I"
Set dsh = Sheets("Echannel-OTA")
Case "Q" To "V"
Set dsh = Sheets("Group")
Case "W" To "Z"
Set dsh = Sheets("Comp")
Case "O"
Set dsh = Sheets("owner")
End Select
If shAry(i) Is sh1 Then
If dsh.Range("B44") = "" Then
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh.Range("B44")
Else
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh. _
Cells(Rows.Count, 2).End(xlUp)(2)
End If
Else
If dsh.Range("R44") = "" Then
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh.Range("R44")
Else
shAry(i).UsedRange.Offset(2).SpecialCells(xlCellTypeVisible).Copy dsh. _
Cells(Rows.Count, 11).End(xlUp)(2)
End If
End If
shAry(i).AutoFilterMode = False
Next
Next
End Sub
Appreciate the help!
~Vanessa