Select sheets based on cell value & ignores empty cell with VBA

pedovolia

New Member
Joined
Apr 25, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I want to select multiple sheets at once by refering from range A1 to A6. Below code works just fine if all cell(A1:A6) contain a valid sheet name. However, this code will crash if there is empty or blank cell in between A1:A6. Is there any way to ignore those empty cell in vba?

VBA Code:
Sub Select_Macro1()

Dim ary As Variant
   ary = Application.Transpose(Range("A1:A6").Value)
   Worksheets(ary).Select

End Sub
 

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.
Hi & welcome to MrExcel.
You could use
VBA Code:
   ary = Filter(Evaluate("transpose(if(A1:A6<>"""",A1:A6))"), False, False)
to eliminate blank cells
 
Upvote 0
Solution
Very much thank you, MrExcel Fluff...It works perfectly. My question has been answered in 16 minutes after I posted this thread, really amazed with respond lighting speed. Really appreciate it...
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
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