PDA

View Full Version : [SOLVED:] VBA copy last row data of one sheet col B of workbook to another workbook sheet col A



megaheinz
12-15-2024, 08:29 AM
Dear all,
I would need a modification of the VBA code in attached file "Output" in order to copy paste the data of the source sheet/file ("Source") starting in column B into another workbook sheet, but starting the output in column A!
So far it copies the data also starting in column B of the output file/sheet , but it should start at column A.
I am not able to figure out what needs to be modified.
Thanks a lot for any support
Best regards
megaheinz

p45cal
12-15-2024, 10:58 AM
Untested:
After setting ws add the line:

wsUsedRangeColmCount = ws.UsedRange.Columns.Count
then change:

.Range("B" & FromlastRow).EntireRow.Copy Destination:=nws.Range("A" & ToLastRow)to:
.Range("B" & FromlastRow).Resize(, wsUsedRangeColmCount - 1).Copy Destination:=nws.Range("A" & ToLastRow)
You were copying the entire row, which includes the blank column A.

megaheinz
12-15-2024, 11:54 AM
Hello p45cal, thank you much for your quick reply; your suggestion works after inserting also a row "Dim wsUsedRangeColmCount As Variant".