shift autofilter range in VBA

jerrykern

Board Regular
Joined
Jun 25, 2004
Messages
71
I'm trying to highlight an adjacent cell when a certain value is found in a cell given a range to look through. I used to do this with a simple loop, but now the data has gotten so large that looping takes forever. I'm trying an autofilter workaround to speed things up.

In short, what I think I need is to select a range using autofilter (always one column wide), and then set a new range, shifting one column to the right, so that I can highlight that column.

This is what I've got, but Excel doesn't like my "Set newrange...Offset"

Code:
Sub highlight()

Dim limitrows As Integer
Dim startrow As Integer
Dim whichcolumn As String
Dim highlightcolumn As String
Dim subject As String
Dim myrange As Range
Dim newrange As Range

whichcolumn = InputBox("Which column should I look in?", "Subject Column")
highlightcolumn = InputBox("Which column should I highlight when found?", "Highlight Column")
subject = InputBox("What should I look for?", "Subject")
startrow = Val(InputBox("Which row should I begin with?", "Start Row"))
limitrows = Val(InputBox("How many rows should I look through?", "Row Limit"))


Set myrange = Range(whichcolumn & startrow, whichcolumn & limitrows)


Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False


myrange.AutoFilter Range(whichcolumn & 1, whichcolumn & 1).Column, subject
Set newrange = myrange.Parent.AutoFilter.Range.Cells(1).Offset(0, 1)
newrange.Cells.Interior.Color = RGB(255, 255, 0)
myrange.Parent.AutoFilterMode = False


Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

jerrykern

Board Regular
Joined
Jun 25, 2004
Messages
71
....AAAAND I just answered my own question by removing the "Cells(1)" piece of the "Set newrange" line.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,714
Messages
5,833,279
Members
430,201
Latest member
Deepakpilla36

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top