VBA - Userform match two columns

Anthony86

Board Regular
Joined
Jan 31, 2018
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I'm just starting to learn VBA and I'm wondering if anyone can help me out. I'm trying to match two words in two different columns, if they match then use offset to populate some information from textboxes to the right.

Is it possible to match two?

Any help will be much appreciated :)
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You check equality with the = operator

Code:
If Range("A1").Value = Range("B2").Value Then
    MsgBox "They match!"
End If
 
Upvote 0
Cerfani,

Sorry If I didn't make myself clear from my previous post.. I'm using a userform in excel and hoping to find a match from two different Textboxes in column A & B.

Code:
If TextBox1.Value = Range("A:A") Then
MsgBox "They Match."
End If

Could something like this not work??
 
Upvote 0
Well you need to check each cell's value, you can't do it all at once like that. There is a function though that will search each cell, Range.Find... https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-find-method-excel

Code:
Dim searchResult As Range
Set searchResult = Range("A:A").Find(...
If Not searchResult Is Nothing Then
    MsgBox "You found it on row " & searchResult.Row
End If
Check the page for how to use the function, use the textbox value for the search value. It will return a range object if it finds something.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,181
Messages
6,123,513
Members
449,101
Latest member
mgro123

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