Populate range based on match found between Userform & another range

Lil Stinker

Board Regular
Joined
Feb 16, 2022
Messages
143
Office Version
  1. 2019
Platform
  1. Windows
I have two similar ranges on one worksheet. The first range, let's call it scnRNG ("B3:O90"), has a list of serial numbers in it. The second range, CLRcode ("AA3:AN90"), is the matching range where I would like to populate the letter "Y" in the matching cell of the serial number that is found. For example, if the serial number listed in B3 is found, AA3 should then equal "Y". It's sort of a match game but scnRNG has all the numbers and CLRcode is blank until the number in scnRNG is located.

I have a simple Userform designed already. What I would to have happen is, the user enters a serial number into the Textbox on the Userform. If the serial number matches a serial number in scnRNG, then "Y" is populated in the corresponding cell in CLRcode. The Userform has only one other criteria via an Option Button. If the Option Button is activated by the user and the Textbox number matches in scnRNG then the letter "R" should be entered into the corresponding cell in CLRcode. If there is no match, nothing happens in CLRcode.

scnRNG:
Book1.xlsm
BCDEFGHIJKLMNO
2SERIAL NUMBERS
30114016426444764716494551065318553757275943640765486721
40164017427544804717494851075320554057315945640865536722
50174018427944824718494951095328554257325947640965546724
Sheet1


Then for every matching number entered from the userform, CLRrng would look something like this:
Book1.xlsm
AAABACADAEAFAGAHAIAJAKALAMAN
2Serial Codes
3YRGGGYYYRRGGYY
4RDyRYYYR
Sheet1


The Userform is just one Textbox with an Enter button and an Option Button. It works just like a search box, the user enters a number, hits Enter, enters another number, hits Enter, etc, etc.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim f As Range
  
  If TextBox1.Value = "" Then Exit Sub
  Set f = Range("B3:O90").Find(TextBox1.Text, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then Cells(f.Row, f.Column + 25).Value = IIf(OptionButton1, "R", "Y")
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,237
Messages
6,123,811
Members
449,127
Latest member
Cyko

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