Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Generic sheet selection in a macro

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Generic sheet selection in a macro


How about

Worksheets(1)

etc.

--

HTH

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


"DaveK" wrote in message
...
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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Generic sheet selection in a macro

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

"Bob Phillips" wrote:


How about

Worksheets(1)

etc.

--

HTH

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


"DaveK" wrote in message
...
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?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Generic sheet selection in a macro

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").Worksheet s(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




DaveK wrote:

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?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Generic sheet selection in a macro

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

"Dave Peterson" wrote:

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").Worksheet s(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




DaveK wrote:

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?


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selection copy and insert to other sheet (Macro) VLOOKUP fORMULA Excel Discussion (Misc queries) 8 March 27th 10 02:48 PM
Generic Macro WildWill Excel Discussion (Misc queries) 7 February 2nd 10 02:21 PM
Generic Sheet Names ckrogers Excel Programming 8 January 28th 05 10:26 PM
Generic Sheet Names ckrogers Excel Programming 4 January 25th 05 08:55 PM
Generic Macro Steve Excel Programming 3 January 22nd 04 09:03 PM


All times are GMT +1. The time now is 03:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"