Hy! How can to combine more sheets in one master, without duplicates?
Hy! How can to combine more sheets in one master, without duplicates?
some help, please?
You will need to attach a sample workbook with the sheets in question.
Go Advanced -> Manage Attachments -> Upload
is copy just col A and col B. i want to copy all columns
Put this into a module (not a worksheet)
Option Explicit 'Always start your code with this. You have to declare all variables with DIM and REDIM statements, and that makes the code more robust Sub CombineSheets() Application.ScreenUpdating = False 'Disable screenupdates. Makes the code faster. Dim wb As Workbook 'This workbook Dim ws As Worksheet 'A worksheet Dim masterWs As Worksheet Dim rng As Range 'Range to be copied Dim lastrow As Long 'Helper to store lastrow on a sheet Set wb = ThisWorkbook 'Store this workbook into a variable Set masterWs = wb.Worksheets("Master") 'Set master WS For Each ws In wb.Worksheets 'Loop all worksheets If ws.Name <> "Master" Then 'If worksheet is not the mastersheet lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Find the lastrow on current worksheet ws.Range("A3:AG" & lastrow).Copy lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row + 1 'Find first empty row on master masterWs.Range("A" & lastrow).PasteSpecial xlPasteValues 'Paste range End If Next ws Application.ScreenUpdating = True 'Enable screenupdates again MsgBox "Done" 'tell user End Sub
Tuomas "Banaanas" Savonius
Trying to give back now when I actually can do some VBA
if i run more time the module, in master is duplicated the data from sheets
Modified to cleat Master WS
Option Explicit 'Always start your code with this. You have to declare all variables with DIM and REDIM statements, and that makes the code more robust Sub CombineSheets() Application.ScreenUpdating = False 'Disable screenupdates. Makes the code faster. Dim wb As Workbook 'This workbook Dim ws As Worksheet 'A worksheet Dim masterWs As Worksheet Dim rng As Range 'Range to be copied Dim lastrow As Long 'Helper to store lastrow on a sheet Set wb = ThisWorkbook 'Store this workbook into a variable Set masterWs = wb.Worksheets("Master") 'Set master WS lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row 'Find first non empty row on master If lastrow > 2 Then 'If we have data on worksheet masterWs.Range("A3:AG" & lastrow).ClearContents 'Clear the masterWS first End If For Each ws In wb.Worksheets 'Loop all worksheets If ws.Name <> "Master" Then 'If worksheet is not the mastersheet lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Find the lastrow on current worksheet ws.Range("A3:AG" & lastrow).Copy lastrow = masterWs.Cells(Rows.Count, "A").End(xlUp).Row + 1 'Find first empty row on master masterWs.Range("A" & lastrow).PasteSpecial xlPasteValues 'Paste range End If Next ws Application.ScreenUpdating = True 'Enable screenupdates again MsgBox "Done" 'tell user End Sub
is working. thank you very much
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks