How to reference code to another workbook

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
191
Office Version
  1. 365
Platform
  1. Windows
The following is the start of a vba that I setup but I need to change it to a button on a different worksheet but have the code reference the Worksheet labeled "Exhibit A" for all the code process to work in. Any suggests / advice? I created a forms control button on a tab labeled "start here" for the end user to press.

VBA Code:
Sub ExhibitA_Setup()
'
' ExhibitA_Setup Macro

   Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("A:E").Select
Selection.Delete Shift:=xlToLeft
Columns("C:Z").Select
Selection.Delete Shift:=xlToLeft
Columns("E:Q").Select
Selection.Delete Shift:=xlToLeft
    Columns("H:K").Select
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The first thing you should do is create a reference to the worksheet you want the code to execute on.
VBA Code:
Dim wsExhibitA As Worksheet

    Set wsExhibitA = Sheets("Exhibit A")

You would then use that reference in the rest of the code.
VBA Code:
Sub ExhibitA_Setup()
'
' ExhibitA_Setup Macro

Dim wsExhibitA As Worksheet

    Set wsExhibitA = Sheets("Exhibit A")

    With wsExhibitA
        .Cells.Copy
        .Cells.PasteSpecial Paste:=xlPasteValues
        .Columns("A:E").Delete Shift:=xlToLeft
        .Columns("C:Z").Delete Shift:=xlToLeft
        .Columns("E:Q").Delete Shift:=xlToLeft
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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