Problems identifying row / column position

Mark.B

Board Regular
Joined
Jun 14, 2004
Messages
136
Hi there, I am using the follwing code to identify the row/column position of a particular value within a range of values (in this example, it is a value ranging from 1 to 10).

The probelm is however, If the 'Level' = 1, then the code below returns the row / column position for the value 10. Does anyone know what I am doing worng and how I can correct this.

Regards
Mark


Level = Range("A1").Value

With Worksheets(1).Range("B1:B10")
Set c = .Find(Level, LookIn:=xlValues)
If Not c Is Nothing Then
Level_Address = c.Address(RowAbsolute:=False)
Level_Row = c.Row
Level_Col_Num = c.Column
Level_Col_Let = Mid(c.Address, 2, (InStr(2, c.Address, "$")) - 2)
End If
End With
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,

the method "FIND" will always use the settings which were used before - be it manually or by VBA - therefore it's good practive to specify all relevant arguments

the "1" is part of "10" so your code probably looked to cell"parts"
so, add an argument "LOOKAT"
Code:
Set c = .Find(Level, LookIn:=xlValues, Lookat:=xlWhole)
take a look in the helpfiles about "FIND"

kind regards,
Erik
 
Upvote 0
Try only looking at the Whole part of the cell value..

Code:
    Dim c As Range, ws As Worksheet
    Dim Level_Address As String, Level_Row As Long
    Dim Level_Col_Num As Long, Level_Col_Let As String
    Set ws = Worksheets(1)
    With ws.Range("B1:B10")
        Set c = .Find(what:=ws.Range("A1").Value, lookat:=xlWhole)
        If Not c Is Nothing Then
            Level_Address = c.Address(0)
            Level_Row = c.Row
            Level_Col_Num = c.Column
            Level_Col_Let = Left(ws.Cells(1, c.Column).Address(0, 0), Len(ws.Cells(1, c.Column).Address(0, 0)) - 1)
        End If
    End With
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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