Whats wrong with my loop code here?

Phoenix_Turn

New Member
Joined
May 11, 2011
Messages
37
The purpose of my code is to stop at a cell when the value of my cell equals to the value of my input from the textbook but here it turns into an infinite loop. Can someone make some modifications below to get it to run? thanks!

i = 1

strEx = txtInp.Text

Do Until rngRang.Value = strEx

rngEx.Offset(i, 0).Select
i = i + 1

Loop

rngrngEx.Select
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Code:
i = 1

strEx = txtInp.Text

Do Until [COLOR="Red"]rngEx.Offset(i, 0)[/COLOR].Value = strEx

i = i + 1

Loop

rngEx.Offset(i, 0).Select

Above is case sensitive if you are matching text.
Below would be case insensitive.
Code:
Do Until [COLOR="Red"]LCase(rngEx.Offset(i, 0).Value)[/COLOR] = [COLOR="Red"]LCase(strEx)[/COLOR]
 
Upvote 0
Code:
i = 1

strEx = txtInp.Text

Do Until [COLOR=Red]rngEx.Offset(i, 0)[/COLOR].Value = strEx

i = i + 1

Loop

rngEx.Offset(i, 0).Select
Above is case sensitive if you are matching text.
Below would be case insensitive.
Code:
Do Until [COLOR=Red]LCase(rngEx.Offset(i, 0).Value)[/COLOR] = [COLOR=Red]LCase(strEx)[/COLOR]

Thanks!!! Works now!! :)

also, what can i write so that if the person enters their value into the inputbox and that value is not in any of the cells at all, a msgbox pops up saying "cant be found"?

Any clues?

Thanks!
 
Last edited:
Upvote 0
This is how I might do it.
Code:
    Dim Found As Range
    Dim rngEx As Range
    
    Set rngEx = Range("A1")
    
    If txtInp.Text <> vbNullString Then
    
        Set Found = rngEx.EntireColumn.Find(What:=txtInp.Text, _
                                            LookIn:=xlValues, _
                                            LookAt:=xlWhole, _
                                            SearchOrder:=xlByRows, _
                                            SearchDirection:=xlNext, _
                                            MatchCase:=False)
        If Not Found Is Nothing Then
            i = Found.Row - rngEx.Row
            Found.Select
            MsgBox "i = " & i
        Else
            MsgBox "No match found for " & txtInp.Text, vbExclamation, "No Match Found"
        End If
        
    End If
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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