find number of line feeds in a string

NCL_Flyer

New Member
Joined
Jan 12, 2022
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I have a program where text to be displayed could be 1 or multiple lines. I want to display the text in a specific form and I have multiple forms for 1-line, 2-lines, 3-lines, etc.
All good as long as I know how many lines are being required.
In some cases though, I don't know that, so I need a way to count the number of line-feeds in a string. The string is build by concatenating multiple elements, for example:
msg_text = msg_text & " Year build : " & prod_year & Chr(13)
msg_text = msg_text & " Rent per active day : " & daily_rent & Chr(13)
etc.
The string (msg_text) is passed to a module that handles the display functionality.
In that module I tried to do a search for the first position on a line feed using >> pos = InStr(1, g_text, "Chr(13)") <<
I also tried to use VbNewLine instead of "Chr(13)", but both times no luck, i.e. pos is always 0.

Any ideas?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
To count the line feeds, try taking the length of the string and subtracting its length after replacing all the Chr(13)'s with "" (null string), something like Len(str)-Len(Replace(str,Chr(13),"").
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,571
Members
452,652
Latest member
eduedu

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