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