How can I get the value of a specific column in a range.

rcrumbliss

New Member
Joined
Jan 30, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
this is probably a really lame question, but I can't seem to figure out how to make this work.

I have a range that I have autofiltered. I then need to look at the rows in that range, to see if a certain variable value falls between the values of columns 6 and 7.

For clarification, I have a data set over 25000 entries in size that contain address ranges. Many of these are single addresses (1234-1234 my lane) but most are ranges (1235-1299 my lane)
I can filter down to the street, but am then left with multiple entries. I just need to get the row for the address I am looking for, and then pull information from 2 columns into a different worksheet.

I dont want to use a for...next loop because I need to reduce the clock cycles this is going to take to process.

This is what I thought would work, but it doesnt.

VBA Code:
            Dim rRange As Range, filRange As Range, rng As Range
            
            Set rRange = Sheets("ENTIRE_CENTER").Range("A2:Z30000")
            With rRange
                .AutoFilter
                .AutoFilter Field:=10, Criteria1:=Street
                .AutoFilter Field:=9, Criteria1:=Pfx
                If StrType <> "" And Not IsEmpty(StrType) Then .AutoFilter Field:=11, Criteria1:=StrType
                .AutoFilter Field:=12, Criteria1:=Sfx
                .AutoFilter Field:=15, Criteria1:=Postal
                
                Set filRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
                
                For Each rng In filRange
                    'if StrtNum > min AND StrtNum < Max then = source
                    If StrtNum > rng.Column(6).Value And _
                        StrtNum < rng.Column(7).Value Then
                            If rng.Column(3).Value < 10 Then ctrLoop = "0" & rng.Column(3).Value Else ctrLoop = rng.Column(3).Value
                            OutputTab.Range("N" & y) = "9801" & ctrLoop & rng.Column(4).Value
                    Else
                        'do nothing
                    End If
            
                Next rng
            End With

Can anyone please clue me in on what I need to use instead of rng.Column(#) to access the data?

Thank you in advance
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Could you please provide some example data along with the expected results? About 15 rows should be enough.
Please use the XL2BB tool to post your example.
 
Upvote 0
Could you please provide some example data along with the expected results? About 15 rows should be enough.
Please use the XL2BB tool to post your example.

Here is a snippet of the information that I need to filter. I first filter it using columns I through L and O using the values in the second sheet. Then I need to filter out rows where Sheet1 Column F => StreetNumber (column G in 2nd Sheet) and is <= Row G

As you can see, If I filter down to S 175th ST, I am left with 4 rows of data. In this case rows 7,9,10,11. I know my problem lies in how I am referencing those values as (rng.Column(#).Value) I just don't know what the correct way to look at the value in a specific column of only the visible rows in the sorted data to determine which row contains said value.


sample.xlsx
ABCDEFGHIJKLMNOPQRS
1CenterNameSLICLoopSequenceUnitPrimaryLowPrimaryHighParityPfxStreetNameStreetTypeSfxCityStatePostalCodeHiLowMapCons SequenceConsignee
2KENT98011510156995400S178THSTTUKWILAWA98188X
3KENT9801110101178001789954THPLSSEATACWA98188X
4KENT980111510156994800S178THSTSEATACWA98188XX
5KENT9801120101177991770050THCTSSEATACWA98188XX
6KENT98011251011759817500EMILITARYRDSSEATACWA98188XX
7KENT980113010147004729S175THSTSEATACWA98188X
8KENT9801135101174001749947THLNSSEATACWA98188X
9KENT980114010147304799S175THSTSEATACWA98188X
10KENT980114010148004899S175THSTSEATACWA98188X
11KENT980114510151005199S175THSTSEATACWA98188X
12KENT98011501011739817300EMILITARYRDSSEATACWA98188XX
13KENT98011551011729817200EMILITARYRDSSEATACWA98188XX
14KENT980116010144604499S173RDSTSEATACWA98188X
15KENT980116510147004899S173RDSTSEATACWA98188X
16KENT9801170101172001739947THAVESSEATACWA98188X
17KENT980117510144004699S172NDPLSEATACWA98188X
18KENT980118010147004799S172NDPLSEATACWA98188X
19KENT980118510148004899S172NDPLSEATACWA98188X
20KENT9801190101173991730051STAVESSEATACWA98188XX
All Sequences






sample.xlsx
ABCDEFGHIJKLMNOPQRS
1RegionDistrictDivisionCenterSLICConsigneeStreetNumPreStreetSfxStreetTypePostalSuiteLoopSeqPkgsStopClosedTypeDIAD SAC
203 - WEST REGION76 - NORTHWEST10 - CENTRAL9801 - TUKWILA-TUKWILA98014755S175thST98188 14511KCRouteLY
Data to Sort
 
Upvote 0
This is untested:
VBA Code:
            Dim rRange As Range, filRange As Range, rng As Range
            Application.ScreenUpdating = False
            Set rRange = Sheets("ENTIRE_CENTER").Range("A2:Z30000")
            With rRange
                .AutoFilter
                .AutoFilter Field:=10, Criteria1:=Street
                .AutoFilter Field:=9, Criteria1:=Pfx
                If StrType <> "" And Not IsEmpty(StrType) Then .AutoFilter Field:=11, Criteria1:=StrType
                .AutoFilter Field:=12, Criteria1:=Sfx
                .AutoFilter Field:=15, Criteria1:=Postal
                
                'set filRange to first column only (i.e. col A)
                Set filRange = .Columns(1).Offset(1, 0).SpecialCells(xlCellTypeVisible)
                
                For Each rng In filRange
                    'if StrtNum > min AND StrtNum < Max then = source
                    If StrtNum > rng.Offset(, 5).Value And _
                        StrtNum < rng.Offset(, 6).Value Then
                            If rng.Offset(, 2).Value < 10 Then ctrLoop = "0" & rng.Offset(, 2).Value Else ctrLoop = rng.Offset(, 2).Value
                            OutputTab.Range("N" & y) = "9801" & ctrLoop & rng.Offset(, 3).Value
                    Else
                        'do nothing
                    End If
            
                Next rng
            End With
            Application.ScreenUpdating = True
 
Upvote 0
Just pointing out a couple things. You are using a For Next loop (For Each...Next)

If's don't require an Else, there is no need for Else 'Do Nothing just leave it off. I didn't check the code other than this.

VBA Code:
                  If StrtNum > rng.Offset(, 5).Value And _
                        StrtNum < rng.Offset(, 6).Value Then
                            If rng.Offset(, 2).Value < 10 Then ctrLoop = "0" & rng.Offset(, 2).Value Else ctrLoop = rng.Offset(, 2).Value
                            OutputTab.Range("N" & y) = "9801" & ctrLoop & rng.Offset(, 3).Value
                    End If
 
Upvote 0

Forum statistics

Threads
1,218,193
Messages
6,141,032
Members
450,332
Latest member
ANTRA

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