vbachanger
New Member
- Joined
- Sep 15, 2021
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hi guys,
I need a code that loops through 7 different chechboxes and if checked, runs the code below.
The code below exports every numeric worksheet name - I need only to export worksheets which are checked.
Thank you!
I need a code that loops through 7 different chechboxes and if checked, runs the code below.
The code below exports every numeric worksheet name - I need only to export worksheets which are checked.
Thank you!
VBA Code:
If UserForm1.CheckBox.Value = True Then
For i = 1 To 7
UserForm1.Controls("CheckBox" & i).Value = True
Next i
End If
Dim Sh As Worksheet
Dim j As Integer
Dim strFile As String
Application.CopyObjectsWithCells = True
For Each Sh In ThisWorkbook.Sheets
For j = 1 To Len(Sh.Name)
If IsNumeric(Mid(Sh.Name, j, 1)) Then
Sh.Copy
With ActiveSheet.UsedRange
.Value = .Value
strFile = ThisWorkbook.FullName
strFile = Left(strFile, InStrRev(strFile, ".") - 1) & "_" & ActiveSheet.Name & ".xlsx"
ActiveWorkbook.SaveAs Filename:=strFile, FileFormat:=xlOpenXMLWorkbook, local:=True
ActiveWorkbook.Close
End With
Exit For
End If
Next j
Next Sh
End Sub