ExcelUser102
New Member
- Joined
- Oct 30, 2010
- Messages
- 6
Hi All,
I am stuck at one point with my macro. I have a macro below which splits the data in my workbook (Attached) into seperate workbooks on the basis of each change in data, and saves the new workbooks with the value available in column A. Everything else works perfectly with this code I just want the code to take the workbook name from Column B, not Column A as it is currently taking. If you take a look at the code below, you will know precisely what I am trying to acheive.
Sub Test()
Dim Sh As Worksheet
Dim Rng As Range
Dim c As Range
Dim List As New Collection
Dim Item As Variant
Dim ShNew As Worksheet
Dim FName As String
Application.ScreenUpdating = False
' *** Change Sheet name to suit ***
Set Sh = Worksheets("Sheet1")
Set Rng = Sh.Range("A2:A" & Sh.Range("A65536").End(xlUp).Row)
On Error Resume Next
For Each c In Rng
List.Add c.Value, CStr(c.Value)
Next c
On Error GoTo 0
Set Rng = Sh.Range("A1:A" & Sh.Range("A65536").End(xlUp).Row)
For Each Item In List
Set ShNew = Worksheets.Add
ShNew.Name = Item
Rng.AutoFilter Field:=1, Criteria1:=Item
Sh.Cells.SpecialCells(xlCellTypeVisible).Copy ShNew.Range("A1")
ShNew.Copy
FName = ThisWorkbook.Path & "\" & Item & ".csv"
ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
Rng.AutoFilter
Next Item
Sh.Activate
Application.ScreenUpdating = True
End Sub
any help on this is highly appreciated as i am trying to find a solution to this for quiet some time now.
Thanks alot
Riz
I am stuck at one point with my macro. I have a macro below which splits the data in my workbook (Attached) into seperate workbooks on the basis of each change in data, and saves the new workbooks with the value available in column A. Everything else works perfectly with this code I just want the code to take the workbook name from Column B, not Column A as it is currently taking. If you take a look at the code below, you will know precisely what I am trying to acheive.
Sub Test()
Dim Sh As Worksheet
Dim Rng As Range
Dim c As Range
Dim List As New Collection
Dim Item As Variant
Dim ShNew As Worksheet
Dim FName As String
Application.ScreenUpdating = False
' *** Change Sheet name to suit ***
Set Sh = Worksheets("Sheet1")
Set Rng = Sh.Range("A2:A" & Sh.Range("A65536").End(xlUp).Row)
On Error Resume Next
For Each c In Rng
List.Add c.Value, CStr(c.Value)
Next c
On Error GoTo 0
Set Rng = Sh.Range("A1:A" & Sh.Range("A65536").End(xlUp).Row)
For Each Item In List
Set ShNew = Worksheets.Add
ShNew.Name = Item
Rng.AutoFilter Field:=1, Criteria1:=Item
Sh.Cells.SpecialCells(xlCellTypeVisible).Copy ShNew.Range("A1")
ShNew.Copy
FName = ThisWorkbook.Path & "\" & Item & ".csv"
ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
Rng.AutoFilter
Next Item
Sh.Activate
Application.ScreenUpdating = True
End Sub
any help on this is highly appreciated as i am trying to find a solution to this for quiet some time now.
Thanks alot
Riz