Incorrect syntax

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472
Hi,

I can't seem to get this syntax correct. I am trying to select a range in the temporary sheet based on the range with data in column A in the original sheet.

Code:
Range("A2", Sheets("Original").Range("A" & Rows.Count).End(xlUp)).Select

Anybody see where my mistake is?

AMAS
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Perhaps

Code:
Range("A2", Range("A" & Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row)).Select
 
Upvote 0
Also the slightly more compact ..
Code:
Range("A2:A" & Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row).Select
 
Upvote 0
Hi Peter,

One small glitch. When I run this when the Temp sheet is selected it works fine. When another sheet is selected it gives me an Application or Object-defined error (1004).

Here is the code:

Code:
Sub Newsub()
    With Sheets("Temp")
        .Range("A2", Range("A" & Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row)).Select
    End With
End Sub

What do you think?

AMAS
 
Upvote 0
Hi Peter,

One small glitch. When I run this when the Temp sheet is selected it works fine. When another sheet is selected it gives me an Application or Object-defined error (1004).

Here is the code:

Code:
Sub Newsub()
    With Sheets("Temp")
        .Range("A2", [SIZE="5"][COLOR="Red"][B].[/B][/COLOR][/SIZE]Range("A" & Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row)).Select
    End With
End Sub

What do you think?

AMAS
You need another . as I've shown in your code above. Or
Rich (BB code):
With Sheets("Temp")
    .Range("A2:A" & Sheets("Original").Range("A" & Rows.Count).End(xlUp).Row).Select
End With
 
Upvote 0
Thanks again Peter. Just tested it and it works great. Its funny how sometimes something as small as a dot can have such a big influence on the code.

AMAS
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,717
Members
452,939
Latest member
WCrawford

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