Hi, So I have a loop at the bottom of this code and I need it to select the cell A1 in the respective sheet at the end. This code creates a runtime error "select method of range class failed" for some reason and I dont see why.
Code:
Public Sub flattendata()
Application.ScreenUpdating = False
'define which worksheets to be used
Dim ed As Worksheet
Set ed = Worksheets("Event Data")
Dim mpd As Worksheet
Set mpd = Worksheets("Model Participant Data")
Dim ad As Worksheet
Set ad = Worksheets("Attendee Data")
Dim sd As Worksheet
Set sd = Worksheets("Survey Data")
'set worksheets as a collection to be easily looped
Dim coll As New Collection
coll.Add ed
coll.Add mpd
coll.Add ad
coll.Add sd
Dim i As Long
For i = 1 To coll.Count
Dim LR As Long
LR = coll(i).Range("A" & Rows.Count).End(xlUp).Row
Dim flattenrange As Range
Set flattenrange = coll(i).Range("A1:AM" & LR)
Dim TR As Long
TR = LR + 1
With coll(i)
flattenrange.Copy
flattenrange.PasteSpecial Paste:=xlPasteValues
flattenrange.ClearFormats
coll(i).Range("A" & TR & ":AM1048576").Delete
coll(i).Range("A1").Select
End With
Application.CutCopyMode = False
Next i
End Sub