Delete cell and move up

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
103
I have code that stores ranges like "D4" and "E4" in variables x and y respectively. However, I run into a bug with the .delete command... Any ideas on how I can fix this? I also want to have excel move that column up where the clear contents took place.

Code:
Private Sub CommandButton1_Click()


Dim rng As Range
Dim aNumber As Variant
Dim rowNum As Variant
Dim x As Variant
Dim y As Variant


If TextBox1.Value = True Then


aNumber = Sheets("Lookup").Range("C3").Value
Set rng = Sheets("Inventory").Range("D1:D502")


rowNum = Application.Match(aNumber, rng, 0)


x = "D" & rowNum
y = "E" & rowNum


Sheets("Inventory").Range("x").Delete Shift:=xlUp
Sheets("Inventory").Range("y").Delete Shift:=xlUp


End If




End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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