aravindhan_31
Well-known Member
- Joined
- Apr 11, 2006
- Messages
- 672
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi,
I have already got an anwer for this long back from this site. The code was writted by Mr. Krishnakumar
the thread is here : http://www.mrexcel.com/forum/showthread.php?t=236699
i need some changes to be made in this code. The existing code creates and updates the details in the sheets automatically from the master data. I just need the sum of Column I in all the sheets after the last row of Column I.
selecting all the sheets and typing the formula in I column is not possible because, the last row in Column I is different in all the sheets.
In sheet 1, the last row of Column I is Row 15, in sheet 2 Row150 is the last row.
I guess something could be done in macros.
follwing is the existing code:
I have already got an anwer for this long back from this site. The code was writted by Mr. Krishnakumar
the thread is here : http://www.mrexcel.com/forum/showthread.php?t=236699
i need some changes to be made in this code. The existing code creates and updates the details in the sheets automatically from the master data. I just need the sum of Column I in all the sheets after the last row of Column I.
selecting all the sheets and typing the formula in I column is not possible because, the last row in Column I is different in all the sheets.
In sheet 1, the last row of Column I is Row 15, in sheet 2 Row150 is the last row.
I guess something could be done in macros.
follwing is the existing code:
Code:
Sub TestIt()
Dim sWS As Worksheet
Dim Sellers As Range, Seller As Range
Dim lRow As Long, fRow As Integer
Dim CopyRng As Range, ws As Worksheet
Set sWS = Worksheets("Data")
lRow = sWS.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
sWS.Columns(1).Insert
sWS.Range("B1:B" & lRow).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=sWS.Range("A1"), Unique:=True
fRow = sWS.Range("A" & Rows.Count).End(xlUp).Row
Set Sellers = sWS.Range("A2:A" & fRow)
For Each Seller In Sellers
With sWS.Range("B1:B" & lRow)
.AutoFilter Field:=1, Criteria1:=Seller
Set CopyRng = .Offset(0, 0).Resize(.Rows.Count, Columns.Count - 1). _
SpecialCells(xlCellTypeVisible)
On Error Resume Next
Set ws = Sheets(Seller.Value)
On Error GoTo 0
If Not ws Is Nothing Then
CopyRng.Copy
ws.Range("A1").PasteSpecial xlPasteValues
Else
Set ws = Sheets.Add
ws.Name = Seller.Value
CopyRng.Copy
ws.Range("A1").PasteSpecial xlPasteValues
End If
.AutoFilter
End With
Set ws = Nothing
Set CopyRng = Nothing
Next Seller
sWS.Columns(1).Delete
Application.ScreenUpdating = True
End Sub