matching/finding text in 2 cells in worksheet

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158
I want to find the text in a worksheet that resides in two cells (it is a column heading split into 2 cells). What code should I use to find the text string split into 2 cells? Any insight would be helpful! Thanks, Rasberry
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

kkknie

Well-known Member
Joined
Apr 29, 2002
Messages
677
If you mean find as in using the find function it might look something like:

=FIND("ab", D15&E15)

Where the & concatanates (joins) the two strings.

If you mean something else, I'm sure concatanation is part of the answer.

Hope this helps,

K
 

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158
I don't understand how that would work. I need to find the words "Rtn on Equity" in a spreadsheet, and "Rtn on" is in one cell, and "Equity" is in the cell below it.
 

kkknie

Well-known Member
Joined
Apr 29, 2002
Messages
677
How are you searching? Are you using the Edit-Find menu function (ctrl-F)?

K
 

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158

ADVERTISEMENT

Thanks for responding. I am actually writing VBA code. I am trying to write code that searches the spreadsheet for the two consecutive cells and then it will perform another task after it finds those contiguous cells.
 

kkknie

Well-known Member
Joined
Apr 29, 2002
Messages
677
If the cells are in the same row, this might work (untested):
Code:
'
' -Code assumes columns A and B are the headings
'
Sub FindEm()

dim i as long
dim iFound as long
dim sTemp as string

for i = 1 to 1000 'Your first row to your last row
   sTemp = Range("A" & i).value & " " & Range("B" & i).value
   if sTemp = "Rtn on Equity" Then
      iFound = i
      Exit For
   end if
next

'Continue on from here with i as the row number with the found heading

End Sub

This could also be converted into a function and called from a main subroutine.

K
 

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158
Thanks! I haven't got it to work, yet. But it is something to start with. I'm working on getting the coding that will cycle through a range rather than just two columns. Basically the spreadsheet. But this is very helpful!
 

Forum statistics

Threads
1,141,012
Messages
5,703,730
Members
421,312
Latest member
Mooncake1

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
Top