Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

select only the data necessary in this code

excel 2010 vba

Is there a way to change the code below to only select the used data on the sheet?




Dim curWks As Worksheet
Dim templWks As Worksheet
Dim rngToCopy As Range

   On Error GoTo OpeniFinalCustomerWorkbook_Error

Set curWks = ActiveSheet
With curWks
Set rngToCopy = .Range("A1:AU65453", .Range("a1").End(xlToRight).End(xlDown))

Open in new window


Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Avatar of redmondb
redmondb
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

Set rngToCopy = .Range("A1:AU65453", .UsedRange)
?

fordraiders
Dim curWks As Worksheet
Dim templWks As Worksheet
Dim rngToCopy As Range

   On Error GoTo OpeniFinalCustomerWorkbook_Error

Set curWks = ActiveSheet

Set rngToCopy = curWks.UsedRange

Open in new window


could you post the full code... as the code you have there can be shortened to:

Dim templWks As Worksheet
Dim rngToCopy As Range

   On Error GoTo OpeniFinalCustomerWorkbook_Error

Set rngToCopy = ActiveSheet.UsedRange

Open in new window

(no real need for dimming and setting curWks)
Thanks
Thanks, fordraiders (and Steve!).

BTW, if there's any chance that the first row might be blank, it might be safer to use...
Set rngToCopy = Range("A1", ActiveSheet.UsedRange)
(UsedRange "starts" from the first non-blank row and column.)

Regards,
Brian.
No worries Brian, I'm sure you had it covered anyways :)

ATB
Steve.