Rahulwork

Active Member
Joined
Jun 9, 2013
Messages
284
i have a code to consolidate the all sheet into one.

sheet name is consolidate. but whenever i have running this, data copying twice. :(


Code:
Private Sub CommandButton1_Click()

Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Sheets("One").Range("a1:c1").Copy Sheets("consolidate").Range("a1:c1")
    For Each sh In ActiveWorkbook.Worksheets
        If sh.Name <> "consolidate" Then
            With sh
                a = .UsedRange.Offset(1)
                Sheets("consolidate").Range("a" & Sheets("consolidate").Cells(Rows.Count, 1).End(xlUp).Row + 1) _
                        .Resize(UBound(a, 1), UBound(a, 2)) = a
                 Cells(1, 1).Select
            End With
        End If
    Next sh
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True




End Sub

please help.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Is the "Consolidate" sheet blank when you run the macro?
 
Upvote 0
In that case, I'm not sure, as that code is only copying the data once, not twice.
What makes you think it's copying everything twice?
 
Upvote 0
bcoz in other sheet i have total 4 rows which need to be consolidate but now it;s 8 and twice each row.

i meant first 4 rows whch is required then again pasting the same rows
 
Upvote 0
Do you get the data for all sheets & then below the same data again, or do you get the data from the 1st sheet twice & then the 2nd sheet twice etc?
 
Upvote 0
Hi
You must be running the code more than once
IT WOULD BE BETTER TO ADD ONE LINE CODE AT THE VERY BEGGING OF THE CODE TO CLEAR THE CONSOLIDATE SHEET
Any way as you may or may not notice that your code is copping the header from the other sheet so you the line code may be add:
Code:
Sheets("sheet1").Cells.ClearContents

Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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