automatic update in new sheet

aravindhan_31

Well-known Member
Joined
Apr 11, 2006
Messages
672
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I already posted this question, but didnt get the exact solution. kindly help me.
sheet 1 Colum A contains data like this,

Column A

Row 1 A & company

Row 2 B & company

Row 3 A & company

Row 4 C & company

Row 5 B & Company

now what i wanted is, Rows 1, & 3( A & Company) has go to sheet 2, Row 2 & 5 (B & company) has to go to sheet 3, and Row 5 (C & Company) has to go to sheet 4.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
something like;
Code:
Sub test()
With Sheets(1)
.Rows(1).Insert
.[a1].Value = "temp"
.Range("A1:A" & .Range("a" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range( _
        "F1"), Unique:=True
For Each r In .Range("f2:f" & .Range("f" & Rows.Count).End(xlUp).Row)
    Sheets.Add after:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Name = r.Value
With .Columns("a")
    Set c = .Find(r.Value, , , xlWhole)
        If Not c Is Nothing Then
            f = c.Address
            Do
            Sheets(Sheets.Count).Range("a" & Rows.Count).End(xlUp).Offset(1).Value = c.Value
        Set c = .FindNext(c)
        Loop Until f = c.Address
        End If
End With
Next
.Rows(1).Delete
.Columns("f").ClearContents
End With
End Sub
 
Upvote 0
Thanks for ur reply agihcam,

please let me know how to work this code, shuld i just paste this in a module n run the macros or anYg other steps to be done. coz i just pasted this code in a module n ran the macro. "Error 400" is appearing. kindly let me know the procedure to run this code as im new to these excel vbas.

ur prompt reply is really appreciated.
regards
Arvind
 
Upvote 0
the code should goes to standard module ( ie; Module1 ). Can you post sample of your sheet using HTML maker?
 
Upvote 0
xlpic.xls
ABCD
1SellerBuyerQtyRate
2AandCoBros19500
3BandCoRussiancoffee45511
4AandCoBlueBird2958
5AandCoWhiteBird35158
6BandCoRussiancoffee56563
7CandCoRussiancoffee45425
8BandCoRussiancoffee45452
9CandCoWhiteBird3525
10AandCoBlueBird4525
Data




What i need is, Row 2, Row 4, Row 5, Row 10 that is" A and Co" automaticaly it has to go to sheet2( i will rename the sheet2 as "A and Co)

and Row 3, Row 6 and Row 8 that is "B and co" automaticaly it has to go to sheet 3 ( I will rename the sheet3 as B and Co)

and Row 7, Row 9 that is "C and Co" automaticaly it has go to sheet4.( i will rename sheet4 as C and Co .


to be clear, anywhere in sheet1 Column A ( that is from Cell A1 to A65536) contains "A and Co" that row has to go to a sheet2. likewise if column A contans "B and Co" then it has to go an another sheet 3


awaiting for ur help.
arvind
 
Upvote 0
HiArvind,

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

HTH
 
Upvote 0
Thanks a lot

wonderful Kri,

wonderfull dude, thanks a lot, this is what i wanted.
I thank agihcam also for helping me out.

Thank u all once agian.

everything is ok now.
 
Upvote 0
Hi,

I have been using this macro for more than 2 years. I required some changes on this.
The macro creates worksheets based on the unique values of Column A in Data sheet: however so far it was working fine coz the values in column A were not too long.

Now I find many values in column A is more than 40 charecters in length. so the macro stops working there when its too long.
is there a way to make changes in macro to create the sheet name with the limited charactors say 25 and to continue running macros

Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,225,626
Messages
6,186,089
Members
453,336
Latest member
Excelnoob223

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