All worksheet name selection and use the selection to execute the macro on that worksheet

slayer1957

Board Regular
Joined
Jan 9, 2017
Messages
50
Good day,

I have to print checklists for multiple equipment, the heading and some data changes with every print as per code currently below.

The problem i have is that i have multiple worksheets and every time i need to change the sheet number hoping i made to correct selection to print the checklist.

I need to add just a combo box or an array of selection to change the variable that i do not need to go in visual basic editor each time to print from that sheet.

So just to add, i have an index worksheet, all worksheet names is in A1-A10 (example, apples, oranges, banana). The combo box must popup and let me make the selection between apples, oranges, bananas and then print the checklist according to the rows i select in my current code

VBA Code:
Public Sub CustomPrint()
  Dim lPrint As Long
'------------------------------------------------------------
'START ROW SELECTION TO PRINT
Dim UserInput1 As String, X
UserInput1 = InputBox("Please enter START rows that you would like to print")
If UserInput1 = "" Then Exit Sub
X = UserInput1

'END ROW SELECTION TO PRINT
Dim UserInput2 As String, Y
UserInput2 = InputBox("Please enter END rows that you would like to print")
If UserInput2 = "" Then Exit Sub
Y = UserInput2
'------------------------------------------------------------
  For lPrint = X To Y
 
  [A3] = Sheet6.[$I2].Offset(lPrint - 0, 0) '[A3} is the cell value to change every time on the ActiveSheet, Set the cell value to change in [__]
                                            'Range from Sheet number, cell range in second [__], Offset is the starting row and column
  [A4] = Sheet6.[$J2].Offset(lPrint - 0, 0)
 
  [B4] = Sheet6.[$D2].Offset(lPrint - 0, 0)
 
  [E4] = Sheet6.[$G2].Offset(lPrint - 0, 0)
 
  ActiveSheet.PrintOut
  'ActiveSheet.PrintOut Preview:=True
  Next lPrint


End Sub

From the code i have to manually change sheet 6 the whole time where i can just make the selection from a combobox or array and then it prints everytime from that. Please assist
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,103
Messages
6,123,112
Members
449,096
Latest member
provoking

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