Katolux182
New Member
- Joined
- Oct 27, 2023
- Messages
- 7
- Office Version
- 365
Hi Mr Excel Forum,
Following my conversation with Kevin, I post the following issue. I want to copy all the new data from one worksheet to another, using column A as the check for this information. Cells A contains a barcode in alphanumeric form, therefore is unic for each row.
I want to integrate this program into a botton so I can click and get all the new data from a mother sheet.
For the time being it copies, although it copies in the same cell position. ej E on cell E of the new data sheet, while I will want for it to past in the net available cell A on A, E on B, F on C etc)
I dont know how to include a check of Cell A so it only copies new data.
I think I over complicated the code as it takes long for it to do the process.
I include the code, the worksheets are not really relevant and I the have sensite information on them. I am not being able, also, to unstall the addon as it gives me a message error
Thank you for any help I can receive
Following my conversation with Kevin, I post the following issue. I want to copy all the new data from one worksheet to another, using column A as the check for this information. Cells A contains a barcode in alphanumeric form, therefore is unic for each row.
I want to integrate this program into a botton so I can click and get all the new data from a mother sheet.
For the time being it copies, although it copies in the same cell position. ej E on cell E of the new data sheet, while I will want for it to past in the net available cell A on A, E on B, F on C etc)
I dont know how to include a check of Cell A so it only copies new data.
I think I over complicated the code as it takes long for it to do the process.
I include the code, the worksheets are not really relevant and I the have sensite information on them. I am not being able, also, to unstall the addon as it gives me a message error
Thank you for any help I can receive
VBA Code:
Sub CopyNewDataWithFormatting()
Dim x As Workbook, y As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow1 As Long, lastrow2 As Long
Dim destlastrow As Long
Dim newDataRow As Range
Set x = Workbooks.Open("C:\Users\agmzj\OneDrive\Escritorio\2023-08-28_Seriennummern_KOPIE.xlsx") ' Direction of the database
Set y = ThisWorkbook ' Use the workbook where the macro is stored as the destination workbook
Set ws1 = x.Sheets("Schlägerübersicht")
Set ws2 = y.Sheets("Master sheet")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lastrow1 = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
lastrow2 = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row
' Loop through each cell in column A in ws1, starting from A3
For Each newDataRow In ws1.Range("A3:A" & lastrow1)
' Check if the value in ws1's column A exists in ws2's column A
If IsError(Application.Match(newDataRow.Value, ws2.Range("A1:A" & lastrow2), 0)) Then
' Value is not found in ws2, so copy specific cells and preserve formatting to ws2
ws1.Cells(newDataRow.Row, 1).Copy ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 5).Copy ws2.Cells(ws2.Rows.Count, 5).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 6).Copy ws2.Cells(ws2.Rows.Count, 6).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 10).Copy ws2.Cells(ws2.Rows.Count, 10).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 9).Copy ws2.Cells(ws2.Rows.Count, 9).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 11).Copy ws2.Cells(ws2.Rows.Count, 11).End(xlUp).Offset(1, 0)
ws1.Cells(newDataRow.Row, 12).Copy ws2.Cells(ws2.Rows.Count, 12).End(xlUp).Offset(1, 0)
End If
Next newDataRow
' Clear the clipboard
Application.CutCopyMode = False
' Close the database workbook without saving changes
x.Close SaveChanges:=False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "New Data Transfered", vbaExclamation, "New Data Transfered"
End Sub