Data Monkey
New Member
- Joined
- May 27, 2016
- Messages
- 5
I have a piece of code to delete out rows but I need the range to be dynamic.
Currently my code is as follows but I need to change the "4" to be a cell reference as I have a formula that decides where to start the delete from.
Please help!
<Code>
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort. _
SortFields.Add Key:=Range("Table7[[#All],[Customer]]"), SortOn:= _
xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Worksheets("Position Selection")
Rows("4:" & .Rows.Count).Delete
End With
End Sub
</Code>
Currently my code is as follows but I need to change the "4" to be a cell reference as I have a formula that decides where to start the delete from.
Please help!
<Code>
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort. _
SortFields.Add Key:=Range("Table7[[#All],[Customer]]"), SortOn:= _
xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Position Selection").ListObjects("Table7").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Worksheets("Position Selection")
Rows("4:" & .Rows.Count).Delete
End With
End Sub
</Code>