Create text string from input

ihorwitz

New Member
Joined
Oct 16, 2003
Messages
28
Is there a formula that creates a text string as shown below from the following inputs:

Period Start 4
Period End 6
Factor 0.5
Text string 4|0.5;5|0.5;6|0.5

The text string is in a format that a software program requires for an upload file.

Any help appreciated.

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
gaz_chops

Perhaps if I present it differently in a spreadsheet format

A B C D
Period Start Period End Factor Text String
4 6 0.5 4|0.5;5|0.5;6|0.5

The text string needs to return each individual period in the range 4 through 6 an concatenate a "|" together with the factor and ";" after each individual period.

Hopefully this helps
 
Upvote 0
If you have Excel 365 with the TEXTJOIN function:

=TEXTJOIN(";",TRUE,ROW(INDIRECT(A2&":"&B2))&"|"&C2)

confirmed with Control+Shift+Enter. If you don't have TEXTJOIN, you'll probably need a UDF.
 
Upvote 0
If you don't have TEXTJOIN, you'll probably need a UDF.
This would be one way to write such a UDF...
Code:
[table="width: 500"]
[tr]
	[td]Function DateFactor(PeriodStart As Long, PeriodEnd As Long, Factor As Double) As String
  DateFactor = Join(Evaluate("TRANSPOSE(ROW(" & PeriodStart & ":" & PeriodEnd & "))"), "|" & Factor & ";") & "|" & Factor
End Function[/td]
[/tr]
[/table]
The function takes three arguments... the first is the period start number, the second is the period end number and the third is the factor. So, for you example, the formula to put in cell D2 would be this...

=DateFactor(A2,B2,C2)


HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use DateFactor just like it was a built-in Excel function. For example,

=DateFactor(A2,B2,C2)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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