shayanhaque
New Member
- Joined
- Mar 13, 2019
- Messages
- 19
I'm trying to save first column of the each sheet as a separate csv file who's name depends on name of each sheet in work book. Once i'm done saving those sheets i want to open those files one by one to align the data in them. below is my code can you please assist how can i open files from same location (name could be anything depending on saved name)
Sub test()
Dim Ary As Variant
Dim NewBk As Workbook, awb As Workbook
Dim ws As Worksheet
Dim Pth As String
With Application.fileDialog(4)
If .Show = -1 Then Pth = .SelectedItems(1)
if len(pth)=0 then Exit sub
if right(pth,1)<>"" then pth=pth& ""
End With
set awb = Activeworkbook
For Each ws In awb.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
Sub test()
Dim Ary As Variant
Dim NewBk As Workbook, awb As Workbook
Dim ws As Worksheet
Dim Pth As String
With Application.fileDialog(4)
If .Show = -1 Then Pth = .SelectedItems(1)
if len(pth)=0 then Exit sub
if right(pth,1)<>"" then pth=pth& ""
End With
set awb = Activeworkbook
For Each ws In awb.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