VBA help

tawoodwa

New Member
Joined
Jan 9, 2017
Messages
17
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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
.
Code:
ActiveSheet.Range("A1").Select
 
Upvote 0
this only would put the cursor on A1 for the page i was selected on for some reason, it wouldnt do it for all pages in the loop
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top