can a string be too long?

melliot2

New Member
Joined
Jul 12, 2010
Messages
45
Dim ph as String
ph= "PH (LC)"
If InStr(Cells(1, c), ph) Then ph = Cells(1, c)

I am trying to use formula. It works great when the contains cell is short. as in one line in the formula bar. However sometimes it will be much longer up to four lines in the formula bar. Would the lenghth cause it to not set the ph variable to the entire cell contents?:confused:
 
Code:
Dim ph as String
 
ph= "PH (LC)"
If InStr(Cells(1, c).Value, ph, vbTextCompare) Then ph = Cells(1, c).Value
That last statement should be this...
Code:
If InStr(1, Cells(1, c).Value, ph, vbTextCompare) Then ph = Cells(1, c).Value
If you specify the 'compare' argument, then you must include the 'start' argument as well; if you only include three arguments, InStr automatically assumes the first argument is the 'start' argument (followed by the two string arguments).
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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