VBA to replicate values to allign with the longest non empty cell in other columns

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
350
Office Version
  1. 365
Platform
  1. Windows
the below script transfer certain values from sheet1 to sheet 2.. i need to modify it to replicate the values in cell Z4,G29,O27,AA27,D27, and C51 so it will be alligned with the the non empty cell in range column B,C,D. Please see photo

Sub TransferData()
Dim wsStaff As Worksheet
Dim wsGuest As Worksheet
Dim lastRow As Long

' Set references to the worksheets
Set wsStaff = ThisWorkbook.Sheets("sHEET1")
Set wsGuest = ThisWorkbook.Sheets("SHEET2")

' Find the last row in the SHEET2
lastRow = wsGuest.Cells(wsGuest.Rows.Count, "A").End(xlUp).Row + 1

' Transfer data
wsGuest.Cells(lastRow, "A").Value = wsStaff.Range("Z4").Value
wsGuest.Cells(lastRow, "B").Resize(15).Value = wsStaff.Range("B11:B25").Value
wsGuest.Cells(lastRow, "C").Resize(15).Value = wsStaff.Range("V11:V25").Value
wsGuest.Cells(lastRow, "D").Resize(15).Value = wsStaff.Range("AB11:AB25").Value
wsGuest.Cells(lastRow, "E").Value = wsStaff.Range("G29").Value
wsGuest.Cells(lastRow, "F").Value = wsStaff.Range("O27").Value
wsGuest.Cells(lastRow, "G").Value = wsStaff.Range("AA27").Value
wsGuest.Cells(lastRow, "H").Value = wsStaff.Range("D27").Value
wsGuest.Cells(lastRow, "I").Value = wsStaff.Range("C51").Value
End Sub
 

Attachments

  • image_2024-06-22_165052802.png
    image_2024-06-22_165052802.png
    35.2 KB · Views: 15

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Just change

Excel Formula:
wsGuest.Cells(lastRow, "A").Value = wsStaff.Range("Z4").Value

to

Excel Formula:
wsGuest.Cells(lastRow, "A").Resize(15).Value = wsStaff.Range("Z4").Value

Repeat for the E to I lines as well.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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