shayanhaque
New Member
- Joined
- Mar 13, 2019
- Messages
- 19
HI,
I'm trying to run the following code from customized ribbon and wants to run this code for all sheets but when i do that it just skips the second case and exits the program. Can you please assist how can i make this to run in module for all sheets. I'm fairly new to VB and i really appreciate your help.
Sub test()
Dim Ary As Variant
Dim NewBk As Workbook
Dim ws As Worksheet
Dim Pth As String
With Application.fileDialog(4)
If .Show = -1 Then Pth = .SelectedItems(1)
End With
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "Sheet1", "Error log", "JUMPER REPORT", "WIRE LABELS", "TERMINATION COUNT"
Case Else
Ary = ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp)).Value2
ws.Range("V1").Resize(UBound(Ary)).Value = Ary
Set NewBk = Workbooks.Add
NewBk.Sheets(1).Range("A1").Resize(UBound(Ary)).Value = Ary
NewBk.SaveAs FileName:=Pth & "" & ws.Name & ".csv", FileFormat:=xlCSV
NewBk.Close False
Set Ary = Nothing
Set NewBk = Nothing
End Select
Next ws
End Sub
I'm trying to run the following code from customized ribbon and wants to run this code for all sheets but when i do that it just skips the second case and exits the program. Can you please assist how can i make this to run in module for all sheets. I'm fairly new to VB and i really appreciate your help.
Sub test()
Dim Ary As Variant
Dim NewBk As Workbook
Dim ws As Worksheet
Dim Pth As String
With Application.fileDialog(4)
If .Show = -1 Then Pth = .SelectedItems(1)
End With
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "Sheet1", "Error log", "JUMPER REPORT", "WIRE LABELS", "TERMINATION COUNT"
Case Else
Ary = ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp)).Value2
ws.Range("V1").Resize(UBound(Ary)).Value = Ary
Set NewBk = Workbooks.Add
NewBk.Sheets(1).Range("A1").Resize(UBound(Ary)).Value = Ary
NewBk.SaveAs FileName:=Pth & "" & ws.Name & ".csv", FileFormat:=xlCSV
NewBk.Close False
Set Ary = Nothing
Set NewBk = Nothing
End Select
Next ws
End Sub