separation of data

alireza123456

New Member
Joined
Aug 3, 2016
Messages
23
Hi
I have a large number of factory data in different sheets and wish separate a specified factory data. please guide me.
for example:
sheet1:
factorysaleincomework day
a102005
b203006
c153005
d55004

<colgroup><col width="70" span="4" style="width:53pt"> </colgroup><tbody>
</tbody>

sheet2:
factorysaleincomework day
b101003
d125004
a142005
f133006
h104005

<colgroup><col width="70" span="4" style="width:53pt"> </colgroup><tbody>
</tbody>

sheet 3:
factorysaleincomework day
a102005
c203004
f304006
a52005

<colgroup><col width="70" span="4" style="width:53pt"> </colgroup><tbody>
</tbody>

i want:
factorysaleincomework day
a102005
a142005
a102005
a52005

<colgroup><col width="70" span="4" style="width:53pt"> </colgroup><tbody>
</tbody>
 
Hello Alizera,

In the code above, add the following line:-

Code:
ws1.UsedRange.Offset(1).ClearContents

just after this line:-

Code:
fSearch = ws1.Range("D1").Value

This will clear the "Summary" sheet before any new transfer of data which means that all the data in the individual sheets will remain.

Next, add the following line:-

Code:
ws1.Range("B" & Rows.Count).End(xlUp)(2).FormulaR1C1 = "=SUM(R2C2:R[-1]C2)"

just after this line:-

Code:
ws1.Range("A" & lr).PasteSpecial xlPasteValues

The formula will total Column B after each transfer.

Cheerio,
vcoolio.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi
thanks dear
it was interesting but my means was not it.
i want a new sheet that consolidate all sheet and in it i can see total income of each id not it's subsection.
thanks for your camaraderie.
 
Upvote 0
Hello Alireza,

I have created another code which can be placed beneath the existing one which should do as you ask. Following are the two codes:-

Code:
Sub SearchShts()

Application.ScreenUpdating = False

        Dim lr As Long
        Dim lr2 As Long
        Dim fSearch As String
        Dim ws As Worksheet
        Dim cell As Range
        Dim ws1 As Worksheet
Set ws1 = Worksheets("Summary")

fSearch = ws1.Range("D1").Value

For Each ws In Worksheets
        If ws.Name <> "Summary" And ws.Name <> "List" Then
        
For Each cell In ws.Range("A2:A" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
  If cell.Value = fSearch Then
     lr = ws1.Range("A" & Rows.Count).End(xlUp).Row + 1
       cell.EntireRow.Copy
         ws1.Range("A" & lr).PasteSpecial xlPasteValues
             ws1.Range("C" & lr).Value = ws.Name
               ws1.Columns.AutoFit
                 End If
             Next
       End If
Next ws
 
ws1.Range("A" & Rows.Count).End(3)(2) = "Total:"
TotalAll
ws1.Range("D1") = "SEARCH"
ws1.Select
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Sub TotalAll()

     Dim ws1 As Worksheet
     Dim lr As Long
     Dim cstart As Long

Set ws1 = Worksheets("Summary")
lr = ws1.Cells(ws1.Rows.Count, "B").End(xlUp).Row
cstart = 2

For i = 2 To lr + 1
    If ws1.Range("B" & i).Value = 0 Or ws1.Range("B" & i) = "" Then
        ws1.Range("B" & i).Formula = "=SUM(B" & cstart & ":B" & i - 1 & ")"
    ElseIf Left(ws1.Range("A" & i).Value, 3) = "Tot" Then
        cstart = i + 1
    End If
Next i

End Sub

As you can probably see, the first code (SearchShts) calls the second code (TotallAll).

Now, every time that you select an ID from the drop down in the search box and click on "GO", the code will bring across to the Summary sheet all data relevant to the selected ID and place a total at the bottom of the data set. When you select a new ID, the same will happen and so on (but only on selection of each ID). All IDs and associated data will be consolidated as "blocks" of data in the Summary sheet with their respective total for Column B. Nothing will be cleared from the Summary sheet.

Following is the link to the updated test work book:-

https://www.dropbox.com/s/hh9lhigckfdcc9s/Alireza(3).xlsm?dl=0

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
Hello Alireza,

You're welcome. I'm glad that I was able to help.

Please mark the thread as solved.

Good luck!

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

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