ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get the position of a cell in Excel named range? (https://www.excelbanter.com/excel-programming/271268-re-how-get-position-cell-excel-named-range.html)

Kalpesh Shah

How to get the position of a cell in Excel named range?
 
'** The code to search some value in the named range
Sub searchInRange(RangeName As String, Value As String)

Dim namedRange As Range
Dim rangecells As Range

Dim mIntCells As Integer
Dim mIntCtr As Integer


Set namedRange = Names(RangeName).RefersToRange
mIntCells = namedRange.Count
Set rangecells = namedRange.Cells

For mIntCtr = 1 To mIntCells
If rangecells.Item(mIntCtr) = Value Then
MsgBox "got it at : " & "row - " & rangecells.Item(mIntCtr).Row & _
"col - " & rangecells.Item(mIntCtr).Column & " -- " &
rangecells.Item(mIntCtr).Address
Exit For
Else
Debug.Print rangecells.Item(mIntCtr).Value
End If
Next
End Sub

'** This is how you will call it
call searchInRange("myrange", "myvalue")

HTH
Kalpesh

"Alan White" wrote in message
...
Hi Groups, I'd like to know if someone could show me how to get the

position
(col, row) of a cell in excel named range. What I need to do is: I will
need to loop through a named range to find a particular cell by value,

once
I found it, I need to know the position of that cell. I'm doing this with
C#, but any VB code would be help too. Thanks!.






All times are GMT +1. The time now is 02:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com