Loop through last cell/row of used range

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

How to write code for this:
Find last cell of Col A of w/sheet used range and match a value of of
userform.textbox1 , loop from last row to first row of used range,if match
found fetch Col B value to userform.textbox2.
Say my usedrange is A1:C123,goto A123 ,match "Xyz"(textbox1 value) loop
through A123 to A1 ,find match.
 
S

Sheeloo

Use
'Make sure that userform.textbox1 is the correct way to get the value in
textbox1

Sub fetch()
For i = Right(ActiveSheet.UsedRange.Address, 2) To 1 Step -1
If Cells(i, 1) = userform.textbox1 Then
userform.textbox2 = Cells(i, 2)
Exit Sub userform.textbox1 & " Not found."
Next i
Msgbox
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top