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
Microsoft Excel

Avatar of undefined
Last Comment
Steve

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
redmondb

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Fordraiders

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

fordraiders
Steve

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)
ASKER
Fordraiders

Thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
redmondb

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.
Steve

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

ATB
Steve.