How do I convert text ie apple to string "apple" in excel or VBA?

marc005

Board Regular
Joined
Apr 21, 2013
Messages
58
How do I convert text ie apple to string "apple" in excel or VBA?
I need the text as a string to use MATCH. I have looked everywhere but cant find a way.

for example: if you put kk in cell A1, pp in cell B1 and rr in cell C1 and then in some
other cell you put =MATCH(kk,A1:C1) it will not work you need to
put =MATCH("kk",A1:C1)

Also if you want to convert text to string it will not work to put for
example ="a1". if you manually type =MATCH("kk",A1:C1) it is ok but since
the code run in VBA I cant type this manually hence I need to convert all
text elements in a range to strings. Complicated!
 
@ZAX that works great :-) I have been looking for this for several days ha ha
One thing to note though:

Public Sub ff()
Range("A5").Formula = "=MATCH(""kk"",A1:C1)"
End Sub

This works fine if the texts in A1, B1 and C1 are alphabetically ordered like in your example kk, pp, rr

But try with pp, rr, kk and see what happens.

You need the 3rd argument = 0 (exact match)

Public Sub ff()
Range("A5").Formula = "=MATCH(""kk"",A1:C1,0)"
End Sub


M.
 
Upvote 0

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.
Yes @Noris you are right I forgot to assign the output to a cell. All the three versions below works. Thanx for your help ;.)

Public Sub fff()
Range("A10").Formula = Application.Match(Range("A1").Value, Range("A1:C1").Value)
End Sub

Public Sub ffff()
Worksheets("Sheet3").Range("A5").Formula = Application.Match(Worksheets("Sheet3").Range("A1").Value, Worksheets("Sheet3").Range("A1:C1").Value)
End Sub

Public Sub fffff()
Worksheets("Sheet3").Range("A5").Formula = Application.Match(Sheets("Sheet3").Range("A1").Value, Sheets("Sheet3").Range("A1:C1").Value)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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