davedave24
Programmer
I have a set of addresses that are 3-5 lines, that go into various worksheet cells that are often 2, 3 or 5 lines. The cells they go into are merged cells.
How would I use Replace() to replace the vbNewLine with ", " but only on certain occurrences?
For example the address is stored in this format (in a single cell):
Address Line 1
Address line 2
Address line 3
Address line 4
Address line 5
These need to go into a merged cell like this:
Address line 1, address line 2
Address line 3, address line 4, address line 5
Or sometimes with 3 lines, like this:
address line 1
address line 2, address line 3
address line 4, address line 5
I can use:
But how do we do this for multiple occurences?
Would it be easier to just paste the formula into the cells and use the excel function Substitute()? If so then I have that already working as thus:
(for 3 line address)
for 2 line address
How would I use Replace() to replace the vbNewLine with ", " but only on certain occurrences?
For example the address is stored in this format (in a single cell):
Address Line 1
Address line 2
Address line 3
Address line 4
Address line 5
These need to go into a merged cell like this:
Address line 1, address line 2
Address line 3, address line 4, address line 5
Or sometimes with 3 lines, like this:
address line 1
address line 2, address line 3
address line 4, address line 5
I can use:
Code:
replace(textaddress, vbnewline, ", ", 1, 1)
Would it be easier to just paste the formula into the cells and use the excel function Substitute()? If so then I have that already working as thus:
(for 3 line address)
Code:
=SUBSTITUTE(SUBSTITUTE([Note.xlsm]Details!$D$4,CHAR(10),", ",3),CHAR(10),", ",3)
for 2 line address
Code:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([Note.xlsm]Details!$D$4,CHAR(10),", ",1),CHAR(10),", ",2),CHAR(10),", ",2)