I'm really new to programming and I have a spreadsheet I'm working on that I could use some help with. My Columns A and B are two dropdown menus, where B is dependent on A. There are some other columns that use VLookUp to bring up information based on the dropdown, and one other column where I have a simple formula. If I clear out a value from Column "A", I would like the entire row to clear (without losing my formulas), and i would all the cells with values under it to shift up. I've looked up a lot of ways to do this with deleting cells, but I haven't been able to find much with clearing them. My code almost works, but seems pretty inelegant since I'm using the clipboard. I also need to clear out the last row at the end using this code, but when I try it, Excel crashes. Any advice would be most appreciated. Here is my code so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wks As Worksheet
Dim FirstRow As Long
Dim FirstColumn As Long
Dim LastRow As Long
Dim QtyColumn As Long
Dim FormulaRange1 As Range
Dim FormulaRange2 As Range
FirstColumn = 1
QtyColumn = 4
Set wks = ActiveSheet
If Not Application.Intersect(Target, Range("A11:A26")) Is Nothing Then
If IsEmpty(Target.Value) Then
wks.Range("B" & Target.Row).ClearContents
wks.Range("D" & Target.Row).ClearContents
FirstRow = Cells(Target.Row, Target.Column).Row
LastRow = Cells(Rows.count, 1).End(xlUp).Row
Set FormulaRange1 = wks.Range(Cells(Target.Row, Target.Column).Offset(1, 0), wks.Cells(LastRow, "B"))
Set FormulaRange2 = wks.Range(Cells(Target.Row, "D").Offset(1, 0), wks.Cells(LastRow, "D"))
FormulaRange1.Copy
wks.Range(Cells(FirstRow, FirstColumn).Address).PasteSpecial xlPasteValues
FormulaRange2.Copy
wks.Range(Cells(FirstRow, QtyColumn).Address).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
End If
End Sub