VBA Move cells in a column up one

Alotheal

New Member
Joined
Sep 2, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have a project with three lists on the same sheet next to each other.
List 1, 2, 3.
Each list has it's own icon, when I press it, it activates this code.

Sub 1QueryHandler()
'Insert Row
Range("B5").EntireRow.Insert
'Copy and paste XLookup formula
Range("B4").Copy
Range("B5").PasteSpecial xlPasteFormulas
'Prevent from deleting formula
Application.CutCopyMode = False


'Copy static date from dynamic formula
Worksheets("Data").Range("I2").Copy Worksheets("Index").Range("F5")
Worksheets("Index").Range("F5").Value = Worksheets("Data").Range("I2").Value
Application.CutCopyMode = False

'Make active cell job card number entry
Range("A5").Activate
End Sub

Referencing the code up above, when clicked a new row populates (Row 5), a formula and date are brought down. I then input my reference number (B5) and the xlookup formula will populate. When that happens there are other columns that I don't want effected by the addition of a row so I need to shift them back up to their original place. For example when I click and the row is added my data is then moved and I need it grabbed at H6:M20000 and O6:T20000 and I'd need to shift those entire ranges up one to then be H5:M20000 and O6:T20000.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Does it help if you change this line:
VBA Code:
Range("B5").EntireRow.Insert
to this:
VBA Code:
Range("B5").Insert shift:=xlDown
 
Upvote 0
Does it help if you change this line:
VBA Code:
Range("B5").EntireRow.Insert
to this:
VBA Code:
Range("B5").Insert shift:=xlDown

That didn't work, reason being is there are three dynamic lists on one sheet. By shifting it up shifts the other two lists as well. I see where you're coming from though.

The solution I have come to is this, but it is slow and I'm actively trying to make it faster, I need help lol.
I have three handlers (because of three lists) each is a variation of this.

'Shift up List2
Range("H6:H20000").Cut Range("H5:H20000")
Range("M6:M20000").Cut Range("M5:M20000")
Range("P6:P20000").Cut Range("P5:P20000")

'Shift up List3
Range("O6:O20000").Cut Range("O5:O20000")
Range("T6:T20000").Cut Range("T5:T20000")
Range("I6:P20000").Cut Range("I5:P20000")

*List1 doesn't get shifted in this case because it is the active one calling for a new row.

So it is a rough version that, on call, will cut and paste those rows.
If you'd like to view my entire handler to see if it can be optimized here she is.

Sub AC5QueryHandler()
'Insert Row
Range("B5").EntireRow.Insert
'Copy and paste XLookup formula
Range("B4").Copy
Range("B5").PasteSpecial xlPasteAll
'Prevent from deleting formula
Application.CutCopyMode = False

'Copy static date from dynamic formula
Worksheets("Data").Range("I2").Copy Worksheets("Index").Range("F5")
Worksheets("Index").Range("F5").Value = Worksheets("Data").Range("I2").Value
Application.CutCopyMode = False

'Give er time to breathe
Application.Wait (Now + TimeValue("0:00:01"))

'Shift up AC6
Range("H6:H20000").Cut Range("H5:H20000")
Range("M6:M20000").Cut Range("M5:M20000")
Range("P6:P20000").Cut Range("P5:P20000")

'Shift up AC7
Range("O6:O20000").Cut Range("O5:O20000")
Range("T6:T20000").Cut Range("T5:T20000")
Range("I6:P20000").Cut Range("I5:P20000")

'Make active cell job card number entry
Range("A5").Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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