?
Solved

Excel VBA - Find row & column address in worksheet based on 2 match scenerios.

Posted on 2013-01-30
7
Medium Priority
?
624 Views
Last Modified: 2013-01-30
Hello Experts,

I have a worksheet where I need to derive the cell.address off 2 variables.

1st variable:
r = "C1" match to Range ("A1:A60") - this will be my row number of that found cell in range

2nd variable:
c = "C2" match to Range ("D1:X1) - this will be my column number of the found cell in range

Then my cell address would be .Cells(r, c) so I can finish my code.  

I am not remembering my stuff here; how to just get the row number or column number.

Thanks,
Michael
0
Comment
Question by:mike637
7 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 38836512
You can try

r=Range ("A1:A60").find("C1",,,xlwhole).Row
c=Range ("D1:X1").find("C2",,,xlwhole).column
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 38836515
if you declare two range objects (one for  Range ("A1:A60"), and one for  Range ("D1:X1"),  you can loop through each range searching for your criteria. Once you find your criteria you can get the address of the cell. Below is a genreal example.
Dim thisRange As Range
Set thisRange = Range("A1:A60") 
Dim searchValue As Integer
Dim targetAddress As String

Dim cell As Variant
searchValue = 21
For Each cell In thisRange
    If cell = searchValue Then
        targetAddress = cell.Address
    End If
Next cell

Open in new window

0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 38836519
ssaqibh, i like your example better than mine ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Shanan212
ID: 38836524
    Dim r As Long, c As Long
    
        r= Application.WorksheetFunction.Match(Range("C1"), Range("A1:A60"), 0)
        c= Application.WorksheetFunction.Match(Range("C2"), Range("D1:X1"), 0)

Open in new window

0
 

Author Closing Comment

by:mike637
ID: 38836536
Thank you very much!!

Michael
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38836537
aebea, this is the beauty of this site....I often come up with a brilliant solution and then discover that there is a better solution available.
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 38836577
saqib, I agree!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question