Solved

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

Posted on 2013-01-30
7
567 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now