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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
.
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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