Delete cell and move up

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
95
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
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Watch MrExcel Video

Forum statistics

Threads
1,090,482
Messages
5,414,797
Members
403,543
Latest member
rabdorawsh

This Week's Hot Topics

Top