Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generic reference in a Macro
Does this idea help?
Sub indexit() x = Sheets(ActiveSheet.Index - 1).Range("g1") MsgBox x End Sub -- Don Guillett SalesAid Software "Harry's GMail World" wrote in message ps.com... 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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Connecting an excel spreadsheet to a generic letter in Word | Excel Discussion (Misc queries) | |||
Open Outlook with generic message | Excel Discussion (Misc queries) | |||
HOW TO RETRIVE LAST NAME USING EXCEL, IT SHOULD BE GENERIC | Excel Worksheet Functions | |||
Creation of a Generic Macro | Excel Worksheet Functions | |||
Macro to Reference Column Next to Current Reference | Excel Discussion (Misc queries) |