Option Explicit
Sub SavetoWB() 'Excel VBA to export data
Const sPath = "C:\Users\HYMC\theSmallman\Test\"
Dim ar As Variant
Dim i As Integer
Dim owb As Workbook
Range("A3", Range("A" & Rows.Count).End(xlUp)).AdvancedFilter xlFilterCopy, , [T1], True
ar = Range("T2", Range("T2").End(xlDown))
'Loop through all unique instances of the Results from the Advanced Filter.
For i = 1 To UBound(ar)
Range("A3", Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, ar(i, 1)
Range("A3", Range("N" & Rows.Count).End(xlUp)).Copy 'Where Data is from Col A - N
Set owb = Workbooks.Add
owb.Sheets(1).[A1].PasteSpecial xlPasteValues
owb.SaveAs sPath & [A2]
owb.Close False 'Close no save
Next i
[a3].AutoFilter
Columns(20).EntireColumn.Clear
End Sub
Sub split_Symbol()
Dim l As Long, smbl() As String, r As Range
Dim i As Long, lr As Long, lrr As Range, wb As Workbook
Application.ScreenUpdating = False
l = Cells(Rows.Count, 1).End(xlUp).Row
ReDim smbl(1 To 1) As String
smbl(1) = "Test"
For Each r In Range("A1:A" & l)
If r.Value <> "SYMBOL" And Len(r) > 0 Then
If Not UBound(Filter(smbl, r.Value)) > -1 Then
ReDim Preserve smbl(1 To UBound(smbl) + 1) As String
smbl(UBound(smbl)) = r.Value
End If
End If
Next
For i = LBound(smbl) + 1 To UBound(smbl)
Set wb = Workbooks.Add
lr = 2
Windows(ThisWorkbook.Name).Activate
For Each r In Range("A1:A" & l)
If r.Value = smbl(i) Then
r.Resize(1, 14).Copy
With wb
With .Sheets(1)
.[A1:N1] = Array("SYMBOL", " SERIES", " DATE1", " PREV_CLOSE", " OPEN_PRICE", _
" HIGH_PRICE", " LOW_PRICE", " LAST_PRICE", " CLOSE_PRICE", " AVG_PRICE", _
" TTL_TRD_QNTY", " TURNOVER_LACS", " DELIV_QTY", " DELIV_PER")
Set lrr = .Cells(.Rows.Count, 1).End(xlUp)(2)
.Cells(lr, 1).PasteSpecial xlPasteValues
lr = lr + 1
End With
End With
End If
Next
wb.SaveAs Application.ThisWorkbook.Path & "\" & smbl(i)
wb.Close False
Next
Application.ScreenUpdating = True
End Sub
Sub SavetoWB2() 'Excel VBA to export data
Dim ar As Variant
Dim i As Integer
Dim owb As Workbook
Dim fil As String
Dim ws As Worksheet
Set ws = Sheet1
Application.DisplayAlerts = False
Range("A3", Range("A" & Rows.Count).End(xlUp)).AdvancedFilter xlFilterCopy, , [T1], True
ar = Range("T2", Range("T2").End(xlDown))
'Loop through all unique instances of the Results from the Advanced Filter.
For i = 1 To UBound(ar)
fil = "D:\Test\" & ar(i, 1) & ".xlsx"
If Dir(fil) = "" Then: Set owb = Workbooks.Add
Else: Set owb = Workbooks.Open(fil)
End If
owb.Sheets(1).[a1].CurrentRegion.Clear
ws.Range("A3", ws.Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, ar(i, 1)
ws.Range("A3", ws.Range("N" & Rows.Count).End(xlUp)).Copy 'Where Data is from Col A - N
owb.Sheets(1).[a1].PasteSpecial xlPasteValues
owb.SaveAs fil
owb.Close False 'Close no save
Next i
[a3].AutoFilter
Columns(20).EntireColumn.Clear
Application.DisplayAlerts = True
End Sub
Sub SavetoWB3() 'Excel VBA to export data
Dim ar As Variant
Dim i As Integer
Dim owb As Workbook
Dim fil As String
Dim ws As Worksheet
Set ws = Sheet1
Application.DisplayAlerts = False
Range("A1", Range("A" & Rows.Count).End(xlUp)).AdvancedFilter xlFilterCopy, , [T1], True
ar = Range("T2", Range("T2").End(xlDown))
'Loop through all unique instances of the Results from the Advanced Filter.
For i = 1 To UBound(ar)
fil = "D:\Test\" & ar(i, 1) & ".xlsx"
If Dir(fil) = "" Then: Set owb = Workbooks.Add
Else: Set owb = Workbooks.Open(fil)
End If
ws.Range("A1", ws.Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, ar(i, 1)
ws.Range("A2", ws.Range("N" & Rows.Count).End(xlUp)).Copy 'Where Data is from Col A - N
owb.Sheets(1).Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
owb.SaveAs fil
owb.Close False 'Close no save
Next i
[a3].AutoFilter
Columns(20).EntireColumn.Clear
Application.DisplayAlerts = True
End Sub