Dummy Excel
Well-known Member
- Joined
- Sep 21, 2005
- Messages
- 1,004
- Office Version
- 2019
- 2010
- 2007
- Platform
- Windows
hi everyone,
ive recorded a simple macro and it works great although it has hardcoded the range of data ("D2:D1321")
how can i change this so its dynamic to different numbers of rows?
thanks
Sam
ive recorded a simple macro and it works great although it has hardcoded the range of data ("D2:D1321")
how can i change this so its dynamic to different numbers of rows?
Code:
Sub Inventory_Report()
'
' Inventory_Report Macro
'
'
Columns("A:B").EntireColumn.Hidden = True
Columns("F:F").EntireColumn.Hidden = True
Columns("K:L").EntireColumn.Hidden = True
Columns("Q:Q").EntireColumn.AutoFit
Columns("R:R").EntireColumn.Hidden = True
Columns("T:AC").EntireColumn.Hidden = True
Columns("AD:AD").EntireColumn.AutoFit
Columns("AE:AE").EntireColumn.Hidden = True
Columns("D:D").EntireColumn.AutoFit
'Sort Data
ActiveWorkbook.Worksheets("Inventory").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Inventory").Sort.SortFields.Add2 Key:=Range( _
"D2:D1321"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Inventory").Sort
.SetRange Range("A1:AE1321")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("C1").AutoFilter
End Sub
thanks
Sam