adjusting code to active cell for multiple columns based on inputbox

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
394
Office Version
  1. 2016
Platform
  1. Windows
hello

I need modifiying this code
VBA Code:
Sub CommandButton2_Click()
  Dim Search          As Variant
  Dim c               As Range, rng As Range
  Dim sh              As Worksheet
  Dim Response        As VbMsgBoxResult
  Dim msg             As String, FirstAddress As String
  Dim Prompts(1 To 2) As String, Prompt As String
    
  Prompts(1) = "Serial number found On row(s) " & Chr(10) & Chr(10)
  Prompts(2) = "Serial number Not found" & Chr(10) & Chr(10)
  Set sh = ThisWorkbook.Worksheets("list1")
  Set rng = sh.Range("B2:B" & Rows.Count)
 
  Do
    rng.Interior.Color = xlNone
    Do    'display inputbox
      Search = InputBox("Enter Search Number Value:", "Search")
      If StrPtr(Search) = 0 Then Exit Sub 'cancel pressed
    Loop Until Len(Search) > 0
   
    If IsNumeric(Search) Then Search = Val(Search)
    Set c = rng.Find(Search, , xlValues, xlWhole, xlByRows, xlNext, True)
    If Not c Is Nothing Then
      FirstAddress = c.Address
      msg = Prompts(1)
      
Do
    c.Interior.Color = vbYellow
    msg = msg & c.Row & Chr(10)
    c.Activate
    Application.Goto ActiveCell.EntireRow, True
    Set c = rng.FindNext(c)
Loop While Not c Is Nothing And FirstAddress <> c.Address
    Else
      msg = Prompts(2) & Search & Chr(10)
    End If
          
    Response = MsgBox(msg & Chr(10) & "Do you want To make another search?", 36, "Results")
    msg = ""
  Loop Until Response = vbNo
End Sub
the adjusting should search for sepecific item into columns B or C or D also should search by cells number based on inputbox and active the cell and show as row1 . this means when search the item and active the cell should move from cell to another . .when running should show as the first row . the items are mixed with numbers & letters also hyphen .

thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,
to change to search range try replacing this line

VBA Code:
 Set rng = sh.Range("B2:B" & Rows.Count)

with this

VBA Code:
Set rng = sh.Range("B:B,C:C,D:D")


Dave
 
Upvote 0
great ! you answered me part of my question . I no know if you can help me the second part . I want also if I write cell number like B200 or C2000 as I mentioned
also should search by cells number
I no know if there is way to do that . just I want expanding the code for search .
thanks
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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