Macro to refer to the current sheet

CordingBags

New Member
Joined
Mar 7, 2022
Messages
37
Office Version
  1. 2016
Platform
  1. Windows
I have a macro that is designed to copy in a master layout area from one sheet, OD LEG, to another.
The workbook contains in excess of a dozen sheets each with a different unrelated name.
It would like it to apply to whichever sheet I am working on at the time, not just as in this case MENS MAT 1.
Copying the master layout area, which is always on sheet OD LGE, to the current sheet, then returning the cursor to the current sheet.

Current MACRO is set to paste special, formulas, ignoring blanks. Have I got to repeat to paste special formats ignoring blanks or can that be included?

Have tried using "Relative References" during macro record but that didn't help.

Many Thanks
Paul

Sub Copy_In_OD_LGE_Layout()
'
' ActiveWindow.ScrollWorkbookTabs Sheets:=1
Sheets("OD LGE").Select
Range("AJ1:AL318").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
Sheets("MENS EVE LGE 1").Select
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
Range("Q19").Select
End Sub

Sheets("MENS MAT 1").Select
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
The current sheet is called ActiveSheet or if you don't include the sheet name it defaults to the ActiveSheet

VBA Code:
Sub Copy_In_OD_LGE_Layout()
    '
    ' ActiveWindow.ScrollWorkbookTabs Sheets:=1
    Sheets("OD LGE").Range("AJ1:AL318").Copy
    ActiveSheet.Range("D1").PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
                                         SkipBlanks:=True, Transpose:=False
    Application.CutCopyMode = False
    ActiveSheet.Range("Q19").Select
End Sub
or
VBA Code:
Sub Copy_In_OD_LGE_Layout()
    '
    ' ActiveWindow.ScrollWorkbookTabs Sheets:=1
    Sheets("OD LGE").Range("AJ1:AL318").Copy
    Range("D1").PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
                                         SkipBlanks:=True, Transpose:=False
    Application.CutCopyMode = False
    Range("Q19").Select
  
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,215,086
Messages
6,123,040
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top