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
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

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!
 

Watch MrExcel Video

Forum statistics

Threads
1,113,862
Messages
5,544,728
Members
410,630
Latest member
JFORTH97
Top