VBA To automatically insert subtotals in multiple worksheets
Closed
vics1000
Posts
2
Registration date
Sunday March 12, 2017
Status
Member
Last seen
March 12, 2017
-
Updated by vics1000 on 12/03/17 at 05:25 AM
vics1000 Posts 2 Registration date Sunday March 12, 2017 Status Member Last seen March 12, 2017 - Mar 12, 2017 at 05:22 AM
vics1000 Posts 2 Registration date Sunday March 12, 2017 Status Member Last seen March 12, 2017 - Mar 12, 2017 at 05:22 AM
Related:
- VBA To automatically insert subtotals in multiple worksheets
- Transfer data from one excel worksheet to another automatically - Guide
- How to insert photo in word for resume - Guide
- Insert check mark in word - Guide
- Vba case like - Guide
- How to insert watermark in word - Guide
1 response
vics1000
Posts
2
Registration date
Sunday March 12, 2017
Status
Member
Last seen
March 12, 2017
Mar 12, 2017 at 05:22 AM
Mar 12, 2017 at 05:22 AM
Sorry this is the code I am currently running to pull the agents info from main sheet
Sub agents()
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim rData As Range
Dim rCl As Range
Dim sNm As String
Set ws = Sheet1
'extract a list of unique names
'first clear existing list
With ws
Set rData = .Range("A1").CurrentRegion
.Columns(.Columns.Count).Clear
rData.Columns(6).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
For Each rCl In .Cells(1, .Columns.Count).CurrentRegion
sNm = rCl.Text
'add new sheet (only if required-NB uses UDF)
If WksExists(sNm) Then
Sheets(sNm).Cells.Clear
Else
'new sheet required
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count) 'move to end
wsNew.Name = sNm
End If
'AutoFilter & copy to relevant sheet
rData.AutoFilter Field:=6, Criteria1:=sNm
rData.Copy Destination:=Worksheets(sNm).Cells(1, 1)
Next rCl
End With
ws.Columns(Columns.Count).ClearContents 'remove temporary list
rData.AutoFilter 'switch off AutoFilter
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
Kind Regards
Hope somebody can help me, I am totally stuck
Sub agents()
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim rData As Range
Dim rCl As Range
Dim sNm As String
Set ws = Sheet1
'extract a list of unique names
'first clear existing list
With ws
Set rData = .Range("A1").CurrentRegion
.Columns(.Columns.Count).Clear
rData.Columns(6).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
For Each rCl In .Cells(1, .Columns.Count).CurrentRegion
sNm = rCl.Text
'add new sheet (only if required-NB uses UDF)
If WksExists(sNm) Then
Sheets(sNm).Cells.Clear
Else
'new sheet required
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count) 'move to end
wsNew.Name = sNm
End If
'AutoFilter & copy to relevant sheet
rData.AutoFilter Field:=6, Criteria1:=sNm
rData.Copy Destination:=Worksheets(sNm).Cells(1, 1)
Next rCl
End With
ws.Columns(Columns.Count).ClearContents 'remove temporary list
rData.AutoFilter 'switch off AutoFilter
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
Kind Regards
Hope somebody can help me, I am totally stuck