automatic update in other sheets: need some changes to the existing code

aravindhan_31

Well-known Member
Joined
Apr 11, 2006
Messages
672
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. 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:

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

In the last row of Col I in Data sheet,

=SUBTOTAL(9,I2:I500)

Replace the 500 with actual last row number.

change the following line

Code:
Set CopyRng = .Offset(0, 0).Resize(.Rows.Count, Columns.Count - 1). _
                SpecialCells(xlCellTypeVisible)

with

Code:
Set CopyRng = .Offset(0, 0).Resize(.Rows.Count+1, Columns.Count - 1). _
                SpecialCells(xlCellTypeVisible)


HTH
 
Upvote 0
Hi Krish & lasw,

Perfect, I got the result. a quick question again, can we make the total in Bold automatically? by the code? coz i got about 125 sheets.

Regards
Arvind
 
Upvote 0
Thanks Lasw,

But I am not sure where to add this line? please help me on this...
 
Upvote 0
Depending on which solution you used for Total in I it will go after

xlPasteValues command -- Kris' method

or

Formula Insert command -- my method
 
Upvote 0
Hi,

Another question on the same code, Sorry if I am troubling much,

on the data sheet, the header that is the first Row, I formated with alingment, colour etc, is it possible to copy the header with the format in other sheets?


Arvind...
 
Upvote 0

Forum statistics

Threads
1,217,054
Messages
6,134,329
Members
449,866
Latest member
veeraiyah

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