Help with a macro to copy adjacent cells

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
41
Office Version
  1. 2016
Platform
  1. Windows
Hi, I’m working on a macro to copy and paste different cells:

Cells(rows.count, “AF”). End(xlup).select
Active cell. Offset(0,-1).select

I have the macro finding the last cell in column AF, coming back up to the first cell with data and then moving one cell to the left “AE” and selecting that cell. I need it to copy cells AE:AG of that row and insert that into AH and shift the cells down to insert. I need it to loop through the rows from bottom to top and do this for each row, if cells in AF have data in them.

Thanks for any help I can get on this. I just can’t find the right code to make all of this happen in the short time I have to get this done.
 
You can change this
Code:
Cells(2, "R").Copy Cells(2, "Af")
Cells(2, "T").Copy Cells(2, "AE")
Cells(2, "S").Copy Cells(2, "AG")
to this
Code:
With Cells(2, 18)
.Offset(, 14).Value = .Value
.Offset(, 15).Value = .Offset(, 1).Value
.Offset(, 13).Value = .Offset(, 2).Value
End With
and this
Code:
If Cells(r, "S") <> Cells(r - 1, "S") Then
'if cell 3 in column s is not equal to cell 2 in column s
Cells(r, "R").Copy Cells(r, "AF")
'copy cell 3 in column R and paste it into column AF
Cells(r, "S").Copy Cells(r, "AG")
'also copy column s and paste into column AG
Cells(r, "T").Copy Cells(r, "AE")
End If
Cells(r - 1, "V").Copy Cells(r - 1, "AH")
to this
Code:
With Cells(r, 19)
If .Value <> .Offset(-1).Value Then
.Offset(, 13).Value = .Offset(, -1).Value
.Offset(, 14).Value = .Value
.Offset(, 12).Value = .Offset(, 1).Value
.Offset(-1, 15).Value = .Offset(-1, 1).Value
End If
End With

Check all the cell references after trying it on a copy of your workbook.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
jolivanes, I took the code replacements and ran the macro and it worked perfectly and the code looks really sleek with those replacements. Thanks for that.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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