Label string to extract numbers from a table

ana1991

New Member
Joined
Sep 29, 2015
Messages
26
Hi all

I'm having a problem in extracting coordinates from a table after writting the name on a label.
Can anyone please help on this?

Thanks in advance!
Ana


My code is currently the following:
(N1 and N2 are the coordinates to extract from the table considering the words on userform1.label1.caption)

Sheets("sheet1").Select
Range("A1").Select
ncategories = WorksheetFunction.CountA(Columns("A:A"))
For i = 1 To ncategories
If Range("A1:A" & ncategories).Cells(i, 1) = UserForm1.Label1.Caption Then
Range("A" & i).Select
N1 = ActiveCell.Offset(UserForm1.Label11.Caption, 1)
N2 = ActiveCell.Offset(UserForm1.Label12.Caption, 2)
End If
Next i
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What are the captions of Label11 & Label12?
Also what are you trying to store in N1 & N2?
 
Upvote 0
What are the captions of Label11 & Label12?
Also what are you trying to store in N1 & N2?
Hi Fluff

Sorry there is a mistake, Label12 should be Label11 as well, so N2 on the code above should be:
N2 = ActiveCell.Offset(UserForm1.Label11.Caption, 2)

Label1 is the surmane of a person. Label11 is the first name of a person with a surmane of Label1.caption.

N1 & N2 are the adress (N1) and zip-code (N2) of the person with first name of "Label11.caption" and surname "Label1.caption"


Thanks a lot
 
Upvote 0
If column A has the surnames, which column has the first name?
 
Upvote 0
Forgot to ask, which columns are address & Zip code?
 
Upvote 0
Ok, how about
VBA Code:
   Dim Cl As Range
   
   With Sheets("sheet1")
      For Each Cl In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
         If Cl.Value = UserForm1.Label1.Caption And Cl.Offset(, 3).Value = UserForm1.Label11.Caption Then
            N1 = Cl.Offset(, 1).Value
            N2 = Cl.Offset(, 2).Value
            Exit For
         End If
      Next Cl
   End With
 
Upvote 0
Solution
Ok, how about
VBA Code:
   Dim Cl As Range
  
   With Sheets("sheet1")
      For Each Cl In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
         If Cl.Value = UserForm1.Label1.Caption And Cl.Offset(, 3).Value = UserForm1.Label11.Caption Then
            N1 = Cl.Offset(, 1).Value
            N2 = Cl.Offset(, 2).Value
            Exit For
         End If
      Next Cl
   End With
It's perfect, thanks a lot Fluff!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,988
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top