save files in csv and then open them from location where files were saved to align data

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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top