Help needed! Formula writing...

will596

New Member
Joined
Oct 29, 2009
Messages
6
Hi!

I have a query and am hoping one of you geniuses can help! I don't even know if it can be done but thought it would be worth asking...

So, I have columns with titles at the top, and with numbers in the below cells.

What I would like is a formula for a column seperate to these that firstly, looks if there is a quantity in the relevant cell on that row, secondly takes the title (top cell) of that column, and thirdly puts the number in the cell on that row after the title:

A_____B_____ C_____ D_____ E______ F
1_____UK____ Ger___ M/E___ Rus_____ Nor
2_____80_____250___ 300___ 350_____200
3____ 60_____200____350____350____ 150

So in cell A1, I would like a formula that reads the subsequent cells and their titles, and gives a one-cell summary of the data seperated by commas. So in A1 it would say:

UK 80, Ger 250, M/E 300, Rus 350, Now 200

And in A2:
UK 60, Ger 200, M/E 350, Rus 350, Now 150

Please help!

Thanks
Will
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi Will, welcome to the Board

I presume you want the information in A2 and A3 etc?

Enter this into A2 and copy down

Code:
=$B$5&" "&$B6&", "&$C$5&" "&$C6&", "&$D$5&" "&$D6&", "&$E$5&" "&$E6&", "&$F$5&" "&$F6

The best way is to copy and paste my formula to be sure of getting the "$" signs in the correct places.

There may be other ways to achieve the same results.
 
Upvote 0
Great, that worked! Thank you very much. And from so close to my Yorkshire home of Harrogate :)

Though I have over twenty headed columns, so now the A2 cell has the headers of each column making it a very wordy cell.

Can the formula be worked so that it only picks up a header and the relevant quantity if there is a value in the quantity cell in the first place?

Thanks
Will
 
Upvote 0
Small world isn't it!

Yes, anything can be done but the possibilities that you are now looking for may be beyond what a formula can reasonably handle - though someone may jump in here with their offering.

Otherwise it may need a User Defined Function.

Regards
 
Upvote 0
With that many columns I would be using a macro to do this. Here's a suggestion.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> CombineText()<br>    <SPAN style="color:#00007F">Dim</SPAN> Result(), rRow(), Headings()<br>    <SPAN style="color:#00007F">Dim</SPAN> Cols <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    Cols = Cells(1, Columns.Count).End(xlToLeft).Column - 1<br>    lr = Range("B:B").Resize(, Cols).Find(What:="?*", After:=Cells(1, 2), _<br>        LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _<br>        SearchFormat:=False).Row<br>    <SPAN style="color:#00007F">ReDim</SPAN> Headings(1 <SPAN style="color:#00007F">To</SPAN> Cols)<br>    <SPAN style="color:#00007F">ReDim</SPAN> rRow(1 <SPAN style="color:#00007F">To</SPAN> Cols)<br>    <SPAN style="color:#00007F">ReDim</SPAN> Result(1 <SPAN style="color:#00007F">To</SPAN> lr)<br>    Headings = Cells(1, 2).Resize(, Cols).Value<br>    <SPAN style="color:#00007F">For</SPAN> r = 2 <SPAN style="color:#00007F">To</SPAN> lr<br>        rRow = Cells(r, 2).Resize(, Cols).Value<br>        <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> Cols<br>            <SPAN style="color:#00007F">If</SPAN> rRow(1, i) <> "" <SPAN style="color:#00007F">Then</SPAN><br>                Result(r) = Result(r) & ", " & Headings(1, i) & " " & rRow(1, i)<br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> i<br>        <SPAN style="color:#00007F">If</SPAN> Result(r) <> "" <SPAN style="color:#00007F">Then</SPAN><br>            Result(r) = Replace(Result(r), ", ", "", 1, 1)<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> r<br>    Cells(1, 1).Resize(lr).Value = Application.Transpose(Result)<br>    Columns("A").AutoFit<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>


Here is the result of running the code with the data shown in cols B:F

Excel Workbook
ABCDEF
1UKGerM/ERusNor
2UK 80, Ger 250, M/E 300, Rus 350, Nor 20080250300350200
3UK 60, Ger 200, M/E 350, Rus 350, Nor 15060200350350150
4UK 25, Nor 3253
5M/E 75.2, Nor 9075.290
6
7Ger 2222
Combine text
 
Upvote 0
Something like this with formula:

Excel Workbook
ABCDEF
1SummaryUKGerM/ERusNor
2UK 80, Ger 250, M/E 300, Rus 350, Nor 200,80250300350200
3Ger 200, Rus 350, Nor 150,200350150
4UK 80, M/E 300, Rus 350, Nor 200,80300350200
5UK 60, M/E 350, Nor 150,60350150
6Ger 250, Rus 350,250350
7UK 60, Ger 200, M/E 350, Rus 350, Nor 150,60200350350150
Sheet8
Excel 2003
Cell Formulas
RangeFormula
A2=IF(B2="","",$B$1 & " " & B2 & ", ") & IF(C2="","",$C$1 & " " & C2 & ", ") &IF(D2="","",$D$1 & " " & D2 & ", ") &IF(E2="","",$E$1 & " " & E2 & ", ")&IF(F2="","",$F$1 & " " & F2 & ", ")



The formula will get quite unwieldy with 20 columns however.

Basically the same unit repeats for each column - IF(B2="","",$B$1 & " " & B2 & ", ") (mind the $ signs).

Yet to fix the trailing comma.
 
Upvote 0
Hi Peter,

Thank you so much for your support. The result is exactly what I am after!

How would I go about writing the macro, is this done with Visual Basic or Microsoft Script Editor?

Best regards
Will
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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