shayanhaque
New Member
- Joined
- Mar 13, 2019
- Messages
- 19
Hi,
I'm trying to copy column one of each sheet and save it to new sheet which will then be saved as csv file and name of new sheet should be pulled from old workbook.
if sheet names are If ShtNames(i) = "Sheet1" Or "Error log" Or "JUMPER REPORT" Or "WIRE LABELS" Or "TERMINATION COUNT" Then it should go to next worksheet else it should run the remaining program.
Please help me in this regard.
I'm trying to copy column one of each sheet and save it to new sheet which will then be saved as csv file and name of new sheet should be pulled from old workbook.
if sheet names are If ShtNames(i) = "Sheet1" Or "Error log" Or "JUMPER REPORT" Or "WIRE LABELS" Or "TERMINATION COUNT" Then it should go to next worksheet else it should run the remaining program.
Please help me in this regard.
Code:
Sub wires()
Dim Ary As Variant
Dim NewBk As Workbook
Dim ws As Worksheet
Dim test As String
Dim ShtNames() As String
ReDim ShtNames(1 To ActiveWorkbook.Sheets.Count)
For i = 1 To Sheets.Count
ShtNames(i) = Sheets(i).Name
Next i
For Each ws In ThisWorkbook.Worksheets
ws.Activate
If ShtNames(i) = "Sheet1" Or "Error log" Or "JUMPER REPORT" Or "WIRE LABELS" Or "TERMINATION COUNT" Then
ActiveSheet.Next.Select
Else
Ary = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value2
Range("V1").Resize(UBound(Ary)).Value = Ary
Set NewBk = Workbooks.Add
NewBk.Sheets(1).Range("A1").Resize(UBound(Ary)).Value = Ary
NewBk.SaveAs Filename:="C:\Path" & test & ".csv", FileFormat:=xlCSV, CreateBackup:=False
'NewBk.SaveAs Filename:="C:\Users\Documents\test_files" mySheet & " .csv", FileFormat:=xlCSV, CreateBackup:=False
Set Ary = Nothing
Set NewBk = Nothing
End If
Next ws
End Sub
Last edited by a moderator: