Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I am trying to VBA code an autofilter on my worksheet (ws_salt)
The autofilter I am trying to accomplish is to filter out all the rows of data, in which the value in column 1 of worksheet "ws_salt", a range of A: the last column of the worksheet with data in it (last_col), is greater than the lower value (f_lr) and less than the upper value (f_ur).
I am getting an error with the line in red. ("Method 'Range' of object '_Global' failed." Based on my unfamiliarity in applying autofilters through VBA, I will assume the remainder of this code is likely also chalked full of errors.
Any help will be greatly appreciated!
Rich (BB code):
Private Sub uf2_create_Click()
Dim f_range As Range
With ws_salt
.AutoFilterMode = False 'turn off autofilter if on
f_lr = ws_sheet2.Cells(i, 11)
f_ur = ws_sheet2.Cells(i, 12)
last_col = .Range("A1").CurrentRegion.Columns.Count
f_range = Range(.Cells(1, 1) & ":" & .Cells(1, last_col))
f_range.AutoFilter field:=1, Criteria1:=">" & f_lr, Operator:=xlFilterValues
f_range.AutoFilter field:=1, Criteria1:="<" & f_ur, Operator:=xlFilterValues
End With
The autofilter I am trying to accomplish is to filter out all the rows of data, in which the value in column 1 of worksheet "ws_salt", a range of A: the last column of the worksheet with data in it (last_col), is greater than the lower value (f_lr) and less than the upper value (f_ur).
I am getting an error with the line in red. ("Method 'Range' of object '_Global' failed." Based on my unfamiliarity in applying autofilters through VBA, I will assume the remainder of this code is likely also chalked full of errors.
Any help will be greatly appreciated!
Last edited: