VBA - Form Search question

Seandobson2402

New Member
Joined
Feb 9, 2018
Messages
23
Hi Guys,

I have created a Form with three Text Boxes - see below;

tPostcode
tStatus
tAvailability

I have three colums on Sheet2 of my workbook detailed Postcode (A), Status (B), Availability (C).

I would like to create a macro (Search button) where I enter a postcode into my tPostcode and it will search through Sheet2 > find the exact value / match and then paste.value the data in the same row but next column (B) into tStatus and the next Column (C) into tAvailability

Say if my search found a postcode for A5, I would like B5 to be copy pasted into tStatus and C5 to be copied into tAvailability

I hope this makes sense.

Also, the form will be accessed through Sheet1 if that makes a difference

Thanks
Sean
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about
Code:
Private Sub CommandButton1_Click()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Sheet2").Range("A:A").find(tpostcode, , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      tstatus = Fnd.Offset(, 1).Value
      tavailability = Fnd.Offset(, 2).Value
   End If
End Sub
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Sheet2").Range("A:A").find(tpostcode, , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      tstatus = Fnd.Offset(, 1).Value
      tavailability = Fnd.Offset(, 2).Value
   End If
End Sub

Thanks Fluff - worked like a charm

I've tried adding code to display a msgbox "No Postcode Found" if there are 0 matching results in Sheet2 Column A however, I seem to have lost it there too. Please see below

Code:
Private Sub Search_Click()
   Dim Fnd As Range
   Dim Qty As Long
   Set Fnd = Sheets("FibreAvail").Range("A:A").Find(tPostcode, , , xlWhole, , , False, , False)
Qty = WorksheetFunction.CountIf((Sheet2), Range("A:A"), Srch)
   If Qty = 0 Then
      MsgBox "No postcode found"
      Exit Sub
   End If
   If Not Fnd Is Nothing Then
      tStatus = Fnd.Offset(, 1).Value
      tAvailable = Fnd.Offset(, 2).Value
   End If
End Sub
 
Upvote 0
Try
Code:
Private Sub CommandButton1_Click()
   Dim Fnd As Range
   Dim a As String
   
   Set Fnd = Sheets("FibreAvail").Range("A:A").find(tpostcode, , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      tstatus = Fnd.Offset(, 1).Value
      tavailability = Fnd.Offset(, 2).Value
   Else
      MsgBox "No postcode found"
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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