Question: How can I copy cells B through Y for all rows based on a unique ID in Column A? I can't copy the entire row, just that range.
screenshot with music data
My method: I copy the sheet > filter > copy visible cells > delete visible cells > move to next filter entry and repeat.
The problem: Some maps (esp. small ones) don't copy. I'd also like a simpler way to do it. I made this file for me just to concat XML together. But now several Mac users are using it and having more problems due to this part of the code.
Sub mapmaker()
Dim LR As Long
Dim Rng As Range
Dim mws As Worksheet
Dim c As Range, i As Long
Dim lastrow As Long, nextrow As Long
Dim cn As Range, rn As Range
Dim output As String
' duplicate sheet with data to copy, set range, see if range contains data
Set rn = Sheets("XML").Range("DR1:DR505")
Application.ScreenUpdating = False
Sheets("Master").Copy After:=Sheets("Master")
ActiveSheet.Name = "MstrCpy"
Sheets("MstrCpy").Select
Range("A1").Select
Set Rng = Worksheets("MstrCpy").Range("A2:A1000")
Set mws = Worksheets("MstrCpy")
If WorksheetFunction.CountA(Rng) < 1 Then Exit Sub
With mws
' count number of entries
i = WorksheetFunction.CountA(Rng)
'turn off any previous filters
If .AutoFilterMode = True Then .AutoFilterMode = False
'loop through cells, filter and copy results
For Each c In .Range("A2:A" & i)
Sheets("XML").Range("A8:X1000").ClearContents
Sheets("MstrCpy").Select
nextrow = Sheets("MstrCpy").Cells(Rows.Count, "A").End(xlUp).Row
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("A1").AutoFilter Field:=1, Criteria1:="=" & Range("A2").Value
.Range("B2:Y" & lastrow).SpecialCells(xlCellTypeVisible).Copy Sheets("XML").Range("A8")
.Range("A2").Copy Sheets("XML").Range("B4")
.Range("B2:Y" & lastrow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
Sheets("MstrCpy").Select
.AutoFilterMode = False
Sheets("XML").Select
output1 = Range("BB2").Value
output2 = Range("BB3").Value
Open output1 For Output As #1
For Each cell In rn
Print #1, cell.Value & Chr(10)
Next
Close
Name output1 As output2
Sheets("MstrCpy").Select
Next c
'turn off filtering
.AutoFilterMode = False
End With
Application.DisplayAlerts = False
Sheets("MstrCpy").Delete
Sheets("Master").Select
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I tend to write things less backwards now. But I don't know VBA well enough to figure this out and my attempts have failed. The similar questions I've seen don't seem to be useful here. Any help would be greatly appreciated and would aid more people than just myself. Thank you!
-Sean