Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Generic reference in a Macro

Would like to have a macro to transfer data from one sheet to the new
one.

I have a Feb sheet with data and want to transfer data to the NEW Mar
sheet.

Problem is that to do a MACRO for Mar from Feb-which works- would not
work in Apr to take data from Mar because the macro only sees for the
Mar from Feb named worksheets/macro.

Need to change the reference (previous month) to a generic
recognizable by the MACRO for all months.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Generic reference in a Macro

You'll need two variables in your recorded macro. Put something like this up
near the top of the Sub:

Const SourceSheet = "Feb" ' change to actual sheet name
Const DestSheet = "Mar" ' change to actual sheet name

now look through the code that was recorded and where you see entries like
Worksheets("Feb").Select
change those to
Worksheets(SourceSheet).Select
i.e., replacing "Feb" with SourceSheet
and similarly replacing "Mar" with DestSheet
Note that neither SourceSheet nor DestSheet have the quote marks around them.

For now you'll have to change the code each month, although you could set
those two constants up as variables and actually ask for the sheet names if
you wanted to. Again define the variables to be used up near the start of
the code:

Dim SourceSheet as String
Dim DestSheet as String

SourceSheet = InputBox("Enter Source Sheet Name", "Copy From", "")
If SourceSheet = "" Then
Exit Sub
End If
DestSheet = InputBox("Enter Destination Sheet Name", "Copy To", "")
If DestSheet = "" Then
Exit Sub
End If
and again change those current references to "Feb" and "Mar" to SourceSheet
and DestSheet.

To get into the macro you recorded to edit it, use
Tools | Macro | Macros then highlight the recorded macro and hit the [Edit]
button.

"Harry's GMail World" wrote:

Would like to have a macro to transfer data from one sheet to the new
one.

I have a Feb sheet with data and want to transfer data to the NEW Mar
sheet.

Problem is that to do a MACRO for Mar from Feb-which works- would not
work in Apr to take data from Mar because the macro only sees for the
Mar from Feb named worksheets/macro.

Need to change the reference (previous month) to a generic
recognizable by the MACRO for all months.


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
Connecting an excel spreadsheet to a generic letter in Word Christine Excel Discussion (Misc queries) 2 December 6th 06 10:20 PM
Open Outlook with generic message jamphan Excel Discussion (Misc queries) 0 March 28th 06 03:59 PM
HOW TO RETRIVE LAST NAME USING EXCEL, IT SHOULD BE GENERIC zomex Excel Worksheet Functions 5 November 29th 05 03:36 PM
Creation of a Generic Macro Sondra Excel Worksheet Functions 1 September 13th 05 10:40 PM
Macro to Reference Column Next to Current Reference dolphinv4 Excel Discussion (Misc queries) 2 April 11th 05 08:36 AM


All times are GMT +1. The time now is 09:20 AM.

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

About Us

"It's about Microsoft Excel"