Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello from Steved
Can the message box be change to have 2 options please 1 To cancel if found ( "I have more than one" ) 2 To continue if not found. I Thankyou. Dim res As String, saddr As String Dim RgToSearch As Range, RgFound As Range Dim secondValue As String Set RgToSearch = ActiveSheet.Range("C:C") res = Application.InputBox("Type School Number as 001,8.00 to find the school you are looking for", _ "Find School", , , , , , 2) If res = "False" Then Exit Sub 'exit if Cancel is clicked res = Trim(UCase(res)) If res = "" Then Exit Sub 'exit if no entry and OK is clicked If InStr(1, res, ",", vbTextCompare) = 0 Then MsgBox "Invalid entry" Exit Sub End If v = Split(res, ",") res = Trim(v(LBound(v))) secondValue = Trim(v(UBound(v))) Set RgFound = RgToSearch.Find(what:=res, _ LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) If RgFound Is Nothing Then MsgBox "School " & res & " not found." Exit Sub Else saddr = RgFound.Address Do If RgFound.Offset(0, 1).Text = secondValue Then Application.Goto Reference:= _ RgFound.Offset(0, -1).Address(True, True, xlR1C1) ' commenting out the next line should do it MsgBox "Click to Continue Searching" ' Exit Do End If Set RgFound = RgToSearch.FindNext(RgFound) Loop While RgFound.Address < saddr End If If RgFound.Offset(0, 1).Text < secondValue Then MsgBox " School Not Found" End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Steved
Example for column A Sub Find_First() Dim FindString As String Dim Rng As Range FindString = InputBox("Enter a Search value") If Trim(FindString) < "" Then With Sheets("Sheet1").Range("A:A") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub If you have more then one occurrence of the value this will select the last occurrence. Sub Find_Last() Dim FindString As String Dim Rng As Range FindString = InputBox("Enter a Search value") If Trim(FindString) < "" Then With Sheets("Sheet1").Range("A:A") Set Rng = .Find(What:=FindString, _ After:=.Cells(1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Steved" wrote in message ... Hello from Steved Can the message box be change to have 2 options please 1 To cancel if found ( "I have more than one" ) 2 To continue if not found. I Thankyou. Dim res As String, saddr As String Dim RgToSearch As Range, RgFound As Range Dim secondValue As String Set RgToSearch = ActiveSheet.Range("C:C") res = Application.InputBox("Type School Number as 001,8.00 to find the school you are looking for", _ "Find School", , , , , , 2) If res = "False" Then Exit Sub 'exit if Cancel is clicked res = Trim(UCase(res)) If res = "" Then Exit Sub 'exit if no entry and OK is clicked If InStr(1, res, ",", vbTextCompare) = 0 Then MsgBox "Invalid entry" Exit Sub End If v = Split(res, ",") res = Trim(v(LBound(v))) secondValue = Trim(v(UBound(v))) Set RgFound = RgToSearch.Find(what:=res, _ LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) If RgFound Is Nothing Then MsgBox "School " & res & " not found." Exit Sub Else saddr = RgFound.Address Do If RgFound.Offset(0, 1).Text = secondValue Then Application.Goto Reference:= _ RgFound.Offset(0, -1).Address(True, True, xlR1C1) ' commenting out the next line should do it MsgBox "Click to Continue Searching" ' Exit Do End If Set RgFound = RgToSearch.FindNext(RgFound) Loop While RgFound.Address < saddr End If If RgFound.Offset(0, 1).Text < secondValue Then MsgBox " School Not Found" End If End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub sl()
what = MsgBox("Choose one", vbYesNoCancel, "Thee Options") End Sub "Steved" wrote: Hello from Steved Can the message box be change to have 2 options please 1 To cancel if found ( "I have more than one" ) 2 To continue if not found. I Thankyou. Dim res As String, saddr As String Dim RgToSearch As Range, RgFound As Range Dim secondValue As String Set RgToSearch = ActiveSheet.Range("C:C") res = Application.InputBox("Type School Number as 001,8.00 to find the school you are looking for", _ "Find School", , , , , , 2) If res = "False" Then Exit Sub 'exit if Cancel is clicked res = Trim(UCase(res)) If res = "" Then Exit Sub 'exit if no entry and OK is clicked If InStr(1, res, ",", vbTextCompare) = 0 Then MsgBox "Invalid entry" Exit Sub End If v = Split(res, ",") res = Trim(v(LBound(v))) secondValue = Trim(v(UBound(v))) Set RgFound = RgToSearch.Find(what:=res, _ LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) If RgFound Is Nothing Then MsgBox "School " & res & " not found." Exit Sub Else saddr = RgFound.Address Do If RgFound.Offset(0, 1).Text = secondValue Then Application.Goto Reference:= _ RgFound.Offset(0, -1).Address(True, True, xlR1C1) ' commenting out the next line should do it MsgBox "Click to Continue Searching" ' Exit Do End If Set RgFound = RgToSearch.FindNext(RgFound) Loop While RgFound.Address < saddr End If If RgFound.Offset(0, 1).Text < secondValue Then MsgBox " School Not Found" End If End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello JLGWhiz
Exactly what was required I Thankyou. Steved "JLGWhiz" wrote: Sub sl() what = MsgBox("Choose one", vbYesNoCancel, "Thee Options") End Sub "Steved" wrote: Hello from Steved Can the message box be change to have 2 options please 1 To cancel if found ( "I have more than one" ) 2 To continue if not found. I Thankyou. Dim res As String, saddr As String Dim RgToSearch As Range, RgFound As Range Dim secondValue As String Set RgToSearch = ActiveSheet.Range("C:C") res = Application.InputBox("Type School Number as 001,8.00 to find the school you are looking for", _ "Find School", , , , , , 2) If res = "False" Then Exit Sub 'exit if Cancel is clicked res = Trim(UCase(res)) If res = "" Then Exit Sub 'exit if no entry and OK is clicked If InStr(1, res, ",", vbTextCompare) = 0 Then MsgBox "Invalid entry" Exit Sub End If v = Split(res, ",") res = Trim(v(LBound(v))) secondValue = Trim(v(UBound(v))) Set RgFound = RgToSearch.Find(what:=res, _ LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) If RgFound Is Nothing Then MsgBox "School " & res & " not found." Exit Sub Else saddr = RgFound.Address Do If RgFound.Offset(0, 1).Text = secondValue Then Application.Goto Reference:= _ RgFound.Offset(0, -1).Address(True, True, xlR1C1) ' commenting out the next line should do it MsgBox "Click to Continue Searching" ' Exit Do End If Set RgFound = RgToSearch.FindNext(RgFound) Loop While RgFound.Address < saddr End If If RgFound.Offset(0, 1).Text < secondValue Then MsgBox " School Not Found" End If End Sub |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello Ron
Thankyou. "Ron de Bruin" wrote: Hi Steved Example for column A Sub Find_First() Dim FindString As String Dim Rng As Range FindString = InputBox("Enter a Search value") If Trim(FindString) < "" Then With Sheets("Sheet1").Range("A:A") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub If you have more then one occurrence of the value this will select the last occurrence. Sub Find_Last() Dim FindString As String Dim Rng As Range FindString = InputBox("Enter a Search value") If Trim(FindString) < "" Then With Sheets("Sheet1").Range("A:A") Set Rng = .Find(What:=FindString, _ After:=.Cells(1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Steved" wrote in message ... Hello from Steved Can the message box be change to have 2 options please 1 To cancel if found ( "I have more than one" ) 2 To continue if not found. I Thankyou. Dim res As String, saddr As String Dim RgToSearch As Range, RgFound As Range Dim secondValue As String Set RgToSearch = ActiveSheet.Range("C:C") res = Application.InputBox("Type School Number as 001,8.00 to find the school you are looking for", _ "Find School", , , , , , 2) If res = "False" Then Exit Sub 'exit if Cancel is clicked res = Trim(UCase(res)) If res = "" Then Exit Sub 'exit if no entry and OK is clicked If InStr(1, res, ",", vbTextCompare) = 0 Then MsgBox "Invalid entry" Exit Sub End If v = Split(res, ",") res = Trim(v(LBound(v))) secondValue = Trim(v(UBound(v))) Set RgFound = RgToSearch.Find(what:=res, _ LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False) If RgFound Is Nothing Then MsgBox "School " & res & " not found." Exit Sub Else saddr = RgFound.Address Do If RgFound.Offset(0, 1).Text = secondValue Then Application.Goto Reference:= _ RgFound.Offset(0, -1).Address(True, True, xlR1C1) ' commenting out the next line should do it MsgBox "Click to Continue Searching" ' Exit Do End If Set RgFound = RgToSearch.FindNext(RgFound) Loop While RgFound.Address < saddr End If If RgFound.Offset(0, 1).Text < secondValue Then MsgBox " School Not Found" End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work | Setting up and Configuration of Excel | |||
File Not Found Automatic Cancel | Excel Programming | |||
Input box to cancel sub when Cancel is clicked. | Excel Programming | |||
Disabling 'Cancel' option when saving work (Yes/No/Cancel) | Excel Programming | |||
Cancel Macro is user selects 'cancel' at save menu | Excel Programming |