Help edit code

novice1

Board Regular
Joined
Dec 11, 2007
Messages
146
The code below was design for used columns from Q - V. But I had to add 3 additional columns (N-P) So now I have N - V that is being used. How can I edit this code to include N-P thanks

Code:
Public Sub Find_Counties()

Dim r_Search As Range
Dim r_Items As Range
Dim r_item As Range

On Error Resume Next
Application.ScreenUpdating = False
Set r_Search = Range("T10").CurrentRegion
Set r_Items = r_Search.Cells(2, 1).Resize(Application.CountA(r_Search.Columns(1)) - 1)

If r_Items.Rows.Count < 1 Then Exit Sub 'nothing to find column Q or R

For Each r_item In r_Items.Rows
    r_Search.AutoFilter 4, r_item.Offset(0, 1) 'find state
    r_Search.AutoFilter 5, r_item 'find city
    r_item.Offset(, 2) = r_Search.Offset(1, 5).Resize(r_Search.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
Next
On Error GoTo 0
r_Search.AutoFilter

If r_Items.Rows.Count = 1 Then
    r_Items.Offset(, 2).Value = "[Other]"
Else
    r_Items.Offset(, 2).SpecialCells(xlCellTypeBlanks).Value = "[Other]"
End If
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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
Back
Top