Solved

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

Posted on 2013-01-30
7
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: 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!

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

724 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