Excel 'Concatenate' with Alt+Enter, and then reference to another cell - excel

This should be a simple process, but I am having difficulty producing the right outcome. I am trying to combine three cells into one, with Alt + Enter or Char(10) separating each value. When I use a simple Excel formula =B2 & Char(10) & C2 & Char(10) & D2 and wrap the text of the destination cell, everything seems normal. But if I try to search for a string in that cell (for example, "WS001"), it won't find the correct string. If I use VBA to perform the same function (i.e. ThisWorkbook.Worksheets("Sheet1").Cells(2, 1) = Cells(2, 2) & Chr(10) & Cells(2, 3) & Chr(10) & Cells(2, 4)), I can then search for the string in B2 and it fill find it.
That problem was addressed (to a degree), but then when I try to link the destination cell to a cell in a different Worksheet (=Sheet1!A2), I encounter the same issue where the search function can't find the string. Is there another method of doing this (I'd like to avoid VBA, because if someone has to edit the file/information in the future, they might not know how to change it)?

Can you clarify what you are looking for based on this example? Column A is the catenation of the three columns to the right, with CHAR(10).
Would you be for example searching for "Shane"? What result would you want?
EDIT
I'm having trouble understanding what you're looking for, but hopefully this can send you in the right direction.
This is my result:
B1 is the data to be searched for
The catenated formula is as follows: (This also worked when they were on a different sheet)
=C6 & CHAR(10) & D6 & CHAR(10) & E6
The "Catenated result" search formula is an array formula (ControlShiftEnter to enter formula)
="Row "&MATCH(TRUE,ISNUMBER(FIND($B$1,A6:A8)))
The "Individual result" search formula is also an array formula (ControlShiftEnter to enter formula)
="Column "&MAX(($B$1=C6:E8)*COLUMN(C6:E8))-2
(the minus 2 is because the first Source Value" column is column C (ie 3)

Related

Relatively search all cells above active cell until reach table header instead of absolute cell

I'm not sure how to even ask about this; hopefully this explanation is clear enough.
Using a VBA recorded macro, with the relative selection on, I have a formula that uses the countif($C$656:C656,[#Column1]) (which is actually the cell directly below the Table Header, Column1)
The problem I'm facing is the formula doesn't translate as the variable locations because I don't know how to use relative code to actually tell vba to search all the way up the Table column until you reach the cell directly below the header. It must be relative because the table is not always created on row 655 and has varying numbers of rows within the table itself so I can't tell VBA R[1]C[1]:R[367]c[1] for example.
Below is the formula entered in the cell itself (B656).
=IF(B655="Column2",[#Column1],
IF(COUNTIF($C655:C$656,[#Column1]),
(CONCATENATE(TEXT([#Date],"yyyy-m-d"),
"_",TEXT([#Date],"hhmm-s"),
"_R-"&COUNTIF($C655:C$656,[#Column1]),
IF([#[TRANSACTION FEE ID]]="","","_"&[#[TRANSACTION FEE ID]]))),
[#Column1]))
Below is the VBA translation using the relative button turned on:
'Enter formula in cell under header (INCLUDES REPEATED DATES FOR DIFFERENT SPREADS)
Range("TblAccountTradeHistory[[#Headers],[Column2]]").Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-1]C=""Column2"",[#Column1]," & Chr(10) & "IF(COUNTIF(R[-1]C3:R656C[1],[#Column1])," & Chr(10) & "(CONCATENATE(TEXT([#Date],""yyyy-m-d"")," & Chr(10) & """_"",TEXT([#Date],""hhmm-s"")," & Chr(10) & """_R-""&COUNTIF(R[-1]C3:R656C[1],[#Column1])," & Chr(10) & "IF([#[TRANSACTION FEE ID]]="""","""",""_""&[#[TRANSACTION FEE ID]])))," & Chr(10) & "[#Column1]))"
ActiveCell.Offset(1, 0).Range("A1").Select
'^^^^^^^^^^^^^^^NOTE: THERE'S A SEARCH ALL CELLS ABOVE THIS ROW THROUGH THE HEADER, BUT ABOVE FORMULA SAYS "R[-1]C3:R656C" WILL THAT MESS UP FOR TRANSACTIONS THAT AREN'T THAT LOW?
Anyone have thoughts of how to make this work?
Don't use cell references within tables and much of your problem goes away.
Assuming your table is named "Table1", try inserting a new column titled DataRowsAbove with a formula of =ROW()-ROW(Tables[#Headers]-1
Then insert another column titled Column1Repeated with a formula of =IF([#DataRowsAbove]=0,0,COUNTIF(OFFSET(Table1[#Headers][Column1],1,0,[#DataRowsAbove],1),[#Column1])
The offset is the secret sauce, here. It gives you a range of every Column1 value above the current line without any cell address references.
Then your Column2 formula can be
=IF(
[#Column1Repeated]=0,
[#Column1],
CONCATENATE(
TEXT([#Date],"yyyy-m-d"),
"_",
TEXT([#Date],"hhmm-s"),
"_R-",
[#Column1Repeated],
IF(
[#[TRANSACTION FEE ID]]="",
"",
"_"&[#[TRANSACTION FEE ID]]
)
)
)
If that works for you, then...
If you don't care about those two extra columns showing, you're fine!
If you can insert two new column before A:A, move those two new column into the new A and B columns, then hide those columns, then your worksheet looks the same as it did before except that it starts with column C.
If you can't do either of these, then you have to replace mentions of [#DataRowsAbove] & [#Column1Repeated] with their formulas instead of those two new columns.

Combining two cells in loop VBA (Excel)

I am trying to combine two cells like this:
Lets say that cell 1 is 123 and cell 2 is 321
Then I want cell 3 to look like this:
123 (321)
So if this was in excel and I wanted to do it with two cells, I would just do it like this:
=E2&"("&F2&")"
But in VBA, I'm actually trying to do it with a loop. So that the i value is the row, and the column is constant.
I've tried to do it like this:
ActiveCell.FormulaR1C1 = _
"='Nye_Virksomheder'!R & i & C2 & ""(""&'Nye_Virksomheder'!R & i & C4&"")"""
So "Nye_Virksomheder" is the sheet that i am taking the data from.
But I keep getting an error. Not sure what is wrong. Anyone that is able to figure it out?
Kind regards,
Zebraboard
You have several issues with quotes.
"='Nye_Virksomheder'!R" & i & "C2 & ""("" & 'Nye_Virksomheder'!R" & i & "C4 &"")"""
Note that you don't actually need a loop to write a formula with an increasing row. You can write the formula to the entire range in one go (keeping the row as a relative reference).

how to drag horizontally a formula which is a string fixed

I have the following formula in excel
=MAX(INDIRECT($A2 & "!"&"B2:B5"))
A2 is a cell in the current worksheet, which is the name of a worksheet tab. However what i wish to do is drag the formula horizontally like that of standard excel formulas to reference the cells of the "other" worksheet tab
So if i dragged horizontally i would get:
=MAX(INDIRECT($A2 & "!"&"C2:C5"))
=MAX(INDIRECT($A2 & "!"&"D2:D5"))
etc
This wont work with the formulas as a fixed text..so how would i do this?
This will solve your problem. Though not sure whether this is the best solution.
=MAX(INDIRECT($A2 & "!" & CHAR(COLUMN()+64) & "2:" & CHAR(COLUMN()+64) & "5"))
Another way is
=MAX(INDIRECT($A2 & "!"&ADDRESS(ROW(),COLUMN())&":"&ADDRESS(ROW()+3,COLUMN())))
if you want the range to start in the same row and column on the second sheet and finish three rows down.

Get Range From A Separate Sheet Using a Variable in Excel

Looking to get a range from another sheet based upon the Column Letter which is obtained from the current sheet.
So say that I designate A2 on the current sheet to the letter G.
I would then ask A10 to =AVERAGE('Sheet1'!(A2)2:(A2)999)
So essentially it would be =AVERAGE('Sheet1'!G2:G999)
However, this doesn't work. Anyone have any idea how to make this worK?
You would use the Indirect() function:
=AVERAGE(INDIRECT("'Sheet1'!" & A2 & "2:" & A2 & "999"))

this row number placeholder excel formula

So I am writing some formulas for my spreadsheets and wondered if there was a placeholder for this row number.
For example say I am using the formula:
=C4+SUM(F4:N4)
I know I can autofill this, but what I really want is some stock formula like:
=C{this.row}+SUM(F{this.row}:N{this.row})
Is this possible? Thanks
The function you need is INDIRECT(CELL/RANGE as string)
The INDIRECT function takes in a string and uses it to evaluate a cell or range location. This is where you get the flexibility (aka indirection) that you need.
eg your formula would be:
=INDIRECT("C" & ROW()) + SUM(INDIRECT("F" & ROW() & ":N" & ROW()))

Resources