'Select Sheet chosen via ComboBox
I would like to select cells of an Excel Sheet like
With Sheets("Sheet1")
But instead of the hardcoded Sheetname "Sheet1" I would like to select the one that is selected in the ComboBox1.
Its items are provided by
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(currentsheet.Cells) <> 0 And _
currentsheet.Visible Then
MsgBox currentsheet.Name
ComboBox1.AddItem (currentsheet.Name)
End If
Next i
Solution 1:[1]
I am assuming you populate the ComboBox1 only with values of worksheet names that exist, but maybe not. It's likely causing an error if a ComboBox1.value is an integer or an empty string. You should try:
sheet_name = CStr(ComboBox1.Value)
If Len(sheet_name) > 0 Then
With Sheets(sheet_name)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris Y |
