Solved

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

Posted on 2013-01-30
7
575 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 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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