Generic sheet selection in a macro

G

Guest

I am importing .csv files and creating graphs. I recorded macros to do what
I need, but the sheet names that are created automatically also get stored in
the macros. How do I make them generic to any sheet I import? E.g., select
whatever the first sheet is vs. the name that the macro recorded, which will
not be the same sheet name every time. BTW, the macros reformat the first
column, create a graph, then save the graph in a second sheet with. Since
the macros recorded specific ranges during the graphing portion, how do I
modify the macro to select all data in the same columns, not just A1:A75?
 
B

Bob Phillips

How about

Worksheets(1)

etc.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
G

Guest

Thank you,

How do I select everything in a column vs. just the range the macro
identified? Some sheets will have more rows than others.

DaveK
 
D

Dave Peterson

Another option is to use a variable to represent that new worksheet.

Depending on how you're importing the .csv...

Dim CSVWks As Worksheet
dim myRng as range
Set CSVWks = Workbooks.Open(Filename:="c:\mycsv.csv").Worksheets(1)

'Then maybe you can find the last row in column A:
with csvwks
set myrng = .range("a1",.cells(.rows.count,"A").end(xlup))
'do something with myRng
end with
 
G

Guest

Thanks for the info. I also came up with this

Range("E:E,A:A").Select

Since I do know the columns I need, in this case A and E, this worked just
fine.

Thanks for the suggestion, you actually gave me some ideas for another macro.

Have a good one.

DaveK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top