Text Column Labels -- Can they be based on counting up between two variables?

mcrossler

New Member
Joined
May 31, 2018
Messages
9
I apologize in advance if this has already been covered in this forum but I'm not sure of the correct terminology to use for what I'm trying to do so I can't search for it.

I'm building a price book spreadsheet with one worksheet covering the various pricing inputs (price per foot in length, price per inch in width, starting length, ending length, as well as the possible widths of the item). The second worksheet converts the data into what will be uploaded as CSV to the ecommerce portion of a website.

In the top cells of that second worksheet, I need to label the data, telling the shopping cart the range of data that can be selected in that column's drop down list.

The problem I'm running into is that one cell's label for the drop down data is dependent on the length (in feet) of the items in that cell. In one case the label needs to show the range of lengths, in one foot increments, from 10' to 34'. In another example, the label needs to show a range of sizes from 5' to 42'. In essence, the starting and ending sizes of the label are not constant and are dependent upon whatever is input into the price input worksheet.

In the first example, the website is expecting the first cell, the column's label, to have this text: 10'|11'|12'|13'|14'|15'|16'|17'|18'|19'|20'|21'|22'|23'|24'|25'|26'|27'|28'|29'|30'|31'|32'|33'|34'
The website will then extract the label's data, the text between the pipes, and convert them into rows for the drop down list.

In the second example, the column's label would be: 5'|6'|7'|8'|9'|10'|11'|12'|13'|14'|15'|16'|17'|18'|19'|20'|21'|22'|23'|24'|25'|26'|27'|28'|29'|30'|31'|32'|33'|34'|35'|36'|37'|38'|39'|40'|41'|42'

I could possibly create a nested IF statement, something like =IF(X+2<y,x&"'|"&x+1&"'|"&x+2&"'|"*x+3&"'",if(x+1<y,x&"'|"&x+1&"'|"&x+2&"'",if(x<y,x&"'|"&x+1"'",x&"'") where="" x="" is="" the="" shortest="" length="" and="" y="" longest="" length.=""

Here I used 4 possible lengths, from the shortest, X, to the longest, Y=X+3, but I would have to build this out to 50 nested IF statements to make it work in almost all circumstances, for the various possibilities of the shortest length being 1' to a longest possible length of 50'.

However, I don't really want to build (nor would Excel probably allow me to build) a nested IF statement this large.

Is there a way to start with what's in a cell, count out a new foot segment in text, until it matches the ending length that was input, without nesting a bunch of IF statements or using VBA?

(I'd prefer to not use either because I won't be able to support the price book once it's complete -- in case someone breaks a large, complicated formula or freaks out because of the macro/VBA warning when they open the spreadsheet.)</y,x&"'|"&x+1&"'|"&x+2&"'|"*x+3&"'",if(x+1<y,x&"'|"&x+1&"'|"&x+2&"'",if(x<y,x&"'|"&x+1"'",x&"'")>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

Not entirely sure, but I think this is what you're asking, we need an empty Column in front of the start of the Labels:


Book1
ABCDEFGHIJKLMNOPQR
1FromTo
210'20'10'11'12'13'14'15'16'17'18'19'20'
35'19'5'6'7'8'9'10'11'12'13'14'15'16'17'18'19'
Sheet68
Cell Formulas
RangeFormula
D2=IF(COUNTA($C2:C2)=0,$A2,IF(LEFT($B2,LEN($B2)-1)-LEFT($A2,LEN($A2)-1)$C2:C2),"",LEFT(C2,LEN(C2)-1)+1&"'"))


Formula copied across as far as needed (also copied down and across in my sample to show another set of results).
 
Upvote 0
Thanks, that fixed part of my issue!

I've modified the formula to this:

=IF($A3="","",IF(COUNTA($C3:C3)=0,$A3&"'",IF(($B3-$A3)<COUNTA($C3:C3),"",LEFT(C3,2)+1&"'")))

which puts a blank in spaces beyond the last number (I'm not anticipating a start to end length of more than 50 and am assuming all the possible lengths will all be than 100, so I don't have to deal with 3 digits.)

The above formula gives me a series of something like this.

A B C D E F G H I J K L M N O P Q R
1 From To
2 10' 20' 10' 11' 12' 13' 14' 15' 16' 17' 18' 19' 20'


My next question is how do I get D2:N2 (while ignoring the blanks from O2:*2) so it's all in one cell with pipes between the numbers:
10'|11'|13'|14'|15'|16'|17'|18'|19'|20'
 
Upvote 0
Actually, my formula will deal with basically Any number of digits, not limited to 2.

ALSO, my formula Already puts BLANKs after the last value, so no modification is needed, see below.


Book1
ABCDEFGHIJKLMNOP
1FromTo
210'20'10'11'12'13'14'15'16'17'18'19'20'  
3111'115'111'112'113'114'115'
425789'25793'25789'25790'25791'25792'25793'
Sheet68
Cell Formulas
RangeFormula
E2=IF(COUNTA($C2:D2)=0,$A2,IF(LEFT($B2,LEN($B2)-1)-LEFT($A2,LEN($A2)-1)$C2:D2),"",LEFT(D2,LEN(D2)-1)+1&"'"))
O2=IF(COUNTA($C2:N2)=0,$A2,IF(LEFT($B2,LEN($B2)-1)-LEFT($A2,LEN($A2)-1)$C2:N2),"",LEFT(N2,LEN(N2)-1)+1&"'"))
P2=IF(COUNTA($C2:O2)=0,$A2,IF(LEFT($B2,LEN($B2)-1)-LEFT($A2,LEN($A2)-1)$C2:O2),"",LEFT(O2,LEN(O2)-1)+1&"'"))


As for your modification to the formula, I don't think the whole formula is showing, so I can't comment on it.

Regarding your new request, do you have the TEXTJOIN function?
I Don't have the TEXTJOIN function, so I can only give you a solution using something else.
 
Last edited:
Upvote 0
You're welcome, welcome to the forum.

Glad you got it working with TEXTJOIN, I'm posting my solution for those viewers that don't have the function.


Book1
ABCDEFGHIJKLMNOP
1FromTo
210'20'10'11'12'13'14'15'16'17'18'19'20'
3111'115'111'112'113'114'115'
425789'25793'25789'25790'25791'25792'25793'
5
610'|11'|12'|13'|14'|15'|16'|17'|18'|19'|20'
Sheet68
<table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">D6</th><td style="text-align:left">=SUBSTITUTE(<font color="Blue">SUBSTITUTE(<font color="Red">CONCATENATE(<font color="Green">D2,E2,F2,G2,H2,I2,J2,K2,L2,M2,N2,O2,P2</font>)&"@","'","'|"</font>),"|@",""</font>)</td></tr></tbody></table></td></tr></table><br />
 
Last edited:
Upvote 0
Thank you for providing the non-TEXTJOIN version.
The spreadsheet works perfectly for me but when a colleague who doesn't have Office 365 tried to use it, it broke.

I appreciate your taking the time to post a backward-compatible version!
 
Upvote 0
Thank you for providing the non-TEXTJOIN version.
The spreadsheet works perfectly for me but when a colleague who doesn't have Office 365 tried to use it, it broke.

I appreciate your taking the time to post a backward-compatible version!

You're welcome, thanks for the feedback.

Yes, it's always a good idea to use "Backward" compatible functions when creating an Excel file meant for distribution...cause you don't know what version others are using.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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