How can I add a sheet to the selection in vba?

ChrisMinder

New Member
Joined
Oct 31, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!

I'm a teacher and I use Excel for my school reports. My file contains 4 sheets for each students. The first and fourth page for each student are only printed once. The second and third pages are printed 4 times a year.

I'm trying to create a userform to select the sheets so I can then export them as a PDF. I'm fairly new to VBA.

Can someone tell me which command I can use to add a sheet to a sheets selection? If I only use Select, the sheet is selected but the previous selection is deselected.

Thanks for your help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the forum,

You mean selecting multiple sheets as below:
VBA Code:
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
 
Upvote 0
Yes but in my userform, I have a button for each sheet. I was hoping to find a way that clicking on this button would add this specific sheet to the already selected pages (by the other buttons).

Using your code would mean that I already know the selection but in my case, it will depend of the sheets I need to print.
 
Upvote 0
I have logged off for the day but worksheet.select has a replace parameter, add false to the select statement and it will select the sheet without deselecting the already selected sheet. Eg

Sheets(1).Select False
 
Upvote 1
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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