Problem retrieving data from another worksheet

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

I am having problems retrieving a range of cells from another worksheet.

The following ignores the With/End With and uses the range on the current sheet.

Code:
Private Sub Worksheet_Activate()

    EnableEvents = True
    
    Call BuildMilestoneTasks
        
    MDRows = Sheets("Survey Definitions").Cells(Rows.Count, 1).End(xlUp).Row
    MDColumns = Sheets("Survey Definitions").Cells(3, Columns.Count).End(xlToLeft).Column
    
    With Sheets("Survey Definitions")
    
        TmpArray = Range(Cells(5, 1), Cells(MDRows, MDColumns))
    
    End With
    
    Call BuildStatus

    Application.Goto Range("A1:A1"), scroll:=False
    
    EnableEvents = False
    
End Sub
The following produces a runtime error - Unable to get the Select Property of the Worksheet class

Code:
Private Sub Worksheet_Activate()

    EnableEvents = True
    
    Call BuildMilestoneTasks
        
    MDRows = Sheets("Survey Definitions").Cells(Rows.Count, 1).End(xlUp).Row
    MDColumns = Sheets("Survey Definitions").Cells(3, Columns.Count).End(xlToLeft).Column
    
    With Sheets("Survey Definitions").Select
    
        TmpArray = Range(Cells(5, 1), Cells(MDRows, MDColumns))
    
    End With
    
    Call BuildStatus

    Application.Goto Range("A1:A1"), scroll:=False
    
    EnableEvents = False
    
End Sub
Any help would greatly be appreciated.

Thanks,
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
When you use a With Structure, you must precede range and cells command with a period in order to reference the object referenced by the With Statement.

Try
Rich (BB code):
    With Sheets("Survey Definitions")
        TmpArray = .Range(.Cells(5, 1), .Cells(MDRows, MDColumns))
    End With
 
Upvote 0
Thanks Jonmo1...

I now get - Application-defined or object-defined error.

I tried using the code right after my Worksheet_Activate in my Sheet module and also in my Public module. Same error occurs.

I'm not certain what I am doing wrong.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

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