Capture text from a column in another worksheet - Excel - arrays

I am trying to capture text from a column in another worksheet.
For example:
In Column Y in Worksheet1 - I want to capture the texts in the cells (lets say there are 10 cells with texts out of 30) but miss off the title cell in Y3.
Then I want to display these captured texts in cell L3 in Worksheet2 with text from each cell on a new line within L3.
Is there a way to do this? Will I need to complete this using an array?
Many thanks

Use this formula then select Wrap Text. See the screenshot below. If it serve your purpose then you can implement for Sheet2.
=D4 & CHAR(10) & D5 & CHAR(10) & D6 & CHAR(10) & D7

Related

Dragging down Arrayformla

I have a Arrayformuöla and importrange to import the data in the cell from an spreadsheet to another spreadsheet. I have figured out how and it works. But i have to write or copy paste the formula to each cell down manually and making after the Changes.How can I drag down the formula to fill out autonatically? I have on spreadsheet 1 in cell C2 K2 and L2 data and I want to transfer the 3 Ciollumns to another spreadsheet in the same cell. As i said it is working but if i drag down the formula instaed of c3 k3 l3 to fill out it still the same.
this is my formula
=arrayformula(importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgcQ/edit", "C2") & " " & importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "K2")& " " &importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "L2"))
This goes into second row of the sheet you are using this formula; like lets say you paste this in Cell A2 then C2,K2,L2 of the source sheet are pulled in & as you drag it down subsequent rows of data are auto-pulled.
If your sheet locale uses ; convention instead of comma then you may want to change all the , in the formula.
Try:
=lambda(z,join(" ",index(z,row(),1),index(z,row(),9),index(z,row(),10)))(importrange("14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgcQ", "C1:L100"))
There is more than one way to do that. Basically you're not working with cells specifically but to text that refers to the location of a cell. That's why it doesn't drag. One with be with string management and associating it to the number of row. For example, if you are positioned in the second for row:
=arrayformula(importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgcQ/edit", "C"& ROW()) & " " & importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "K" & ROW())& " " &importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "L" & ROW() ))
You could change ROW() with ROW()+1 if you were starting in row 3 for example.
But, what I'd suggest is to do only once the IMPORTRANGE and use BYROW to do the joining. Let's say you need it until row 100:
=BYROW({importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgcQ/edit", "C2:C100"),importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "K2:K100"),importrange("https://docs.google.com/spreadsheets/d/14cyHIzdBHSFa4hgj0S0bCIFk7CC-zSw4g3ngI7UNgc/edit", "L2:L100")}, LAMBDA(imported, TEXTJOIN(" ",1,imported)))
It would be much more efficient. Let me know if it's useful
Thanks it worked!! both apf the formulas!! thumps up

Google Sheets - Formula to Concatenate Text in Range of Cells based on Numeric Value in Corresponding Range of Cells

I have this setup in Google Sheets:
Row 1 is a list of ingredients. Rows 2-6 are specific plans that contain combinations of ingredients A-F - if there is a 1 in the column, it contains the ingredient in the column.
In column H, I want to concatenate the letters in row 1 if there is a 1 underneath it.
So the formula I'm looking for in Col H should spit out the following:
Cell H2 --> A + B
Cell H3 --> A + C
Cell H4 --> A + B + D
Cell H5 --> A + C + D
Cell H6 --> A
I've tried the TEXTJOIN formula you see in the formula bar but it's not working. Can anyone help with this?
Thanks!
Nevermind, I just figured it out. I had to change my formula above to:
=textjoin(" + ", TRUE, arrayformula(IF($B7:$G7=1, $B$1:$G$1,"")))
Anthony,
If I got it correctly what you want to combine, another option to do that is to use CONCATENATE + IF.
I needed to combine 5 columns but make a note while a cell contains particular data (e.g., when X is in the cell, not to combine columns but write a comment). And the combination of CONCATENATE + IF worked.
I found this solution here.
Hope it'll be somehow helpful :)

Excel - setting a dynamic print area for a range of cells covered by an array formula

I have a spreadsheet with a page (Sheet 3) which I would like to export as a PDF (using a macro to export the pdf).
Currently, this links in to another worksheet, in which a user can put in a date range to pull out relevant data from a larger worksheet. This uses the following array formula to populate the data on Sheet 3:
=IFERROR(INDEX(Sheet1!$V$3:$W$5998,SMALL(IF((Sheet1!$C$3:$C$5998>=Crynodeb!$D$3)*(Sheet1!$C$3:$C$5998<=Crynodeb!$F$3)*(Sheet1!$V$3:$V$5998<>""),ROW(Sheet1!$V$3:$W$5998)-2),ROW(18:18)),1),"")
The array formula on Sheet 3 has been applied to around 6000 rows of data. So there is potential for 6000 lines of data to be returned. However, depending on the criteria the user has put in, maybe only 5 rows of data will be returned.
In addition to this, I've applied cell formatting to the 6000 rows so that there's a print-friendly line in between the rows of data.
However, because this has been applied to the 6000 rows of data, there could be 61 or so pages exported, when in reality only a page worth of data is displaying.
Is there an easy way to continue having the array formula applied across a large range, while limiting the print function to only apply to pages containing data that is returned from the array formula?
I'm also using the Format > AutoFit Row Height function to adjust the row height in accordance to the length of the returned items, but at the moment I think I have to do this manually every time I return data. Is there a way of applying that automatically to adjust around the content of the page?
Many thanks
Since you want to export the data to PDF via macro, we can just put everything you want into that one macro.
The macro needs to find the range that has values. From your example, I'm assuming there will always be data returned starting in A3; and then there will no blanks in Column A until the end of the data.
So, this macro starts at A3 and looks at each cell until it finds a blank value to determine where the data ends.
I'm also assuming you have a fixed number of columns of data. I can only see 2 columns so I've used that figure in macro. You can update the code where indicated to the actual number of columns.
Then, from A1 to the last row and column of the data, it autofits the rows and then saves that range as a PDF.
Public Sub SaveCopy()
Dim intLastRow As Integer
'Loops through column A to find last row with data
intLastRow = 3
Do While Cells(intLastRow + 1, 1).Value <> ""
intLastRow = intLastRow + 1
Loop
'With the range of data...
'NOTE: REPLACE '2' WITH ACTUAL NUMBER OF COLUMNS OF DATA
With Range("A1", Cells(intLastRow, 2))
'Ensure text is wrapping - required to autofit
.WrapText = True
'Autofit row height
.Rows.AutoFit
'Save as PDF
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.FullName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End With
End Sub
This is a basic export and will just save the PDF into the same location as the file and with the same filename (including the excel file extension) and just appends .PDF file extension.
There are various options for handling the filename and location of the PDF. With more information of what is required I could help provide a robust solution.
Alternatively, you can remove the line of code for exporting to PDF and replace it with just ".Select"
This will select the range of data and then you can manually save to PDF. Just use Save As... change the type to PDF, click Options and choose "Selection" in the "Publish what" section.
If any of my assumptions are incorrect, please let me know.

Dynamically referencing cells in other worksheets in Excel?

I have a table of data, a selection of which look like:
BARC 0.0001 0.0003 0.0006 0.0012 0.0009 0.0010 0.0008 0.0024
BNP 0.1915 4.1915 0.2314 0.3147 0.3168 0.3300 0.3060 0.4277
CSGN 0.1915 0.0003 0.2221 0.0104 0.0109 0.0124 0.0097 0.0152
The data in each cell are linked to a separate worksheet which share a name with the names in the first column. Each entry in the table for each column references the same cell but in a different worksheet. So B1 is BARC!G850, B2 is BNP!G850, and B3 IS CSGN!G850. The references are the same for each cell besides the worksheet name, but they don't increase incrementally across the rows; C1 IS BARC!G858 and D1 is BARC!G863, for example.
I want to use a formula to automatically populate the table instead of typing out the worksheet name references by hand. How can I do this?
Using the INDIRECT function you can reference a worksheet based on the text in ColA.
A | B | C
BARC | =INDIRECT( A1&"!G850") | =INDIRECT( A1&"!G858")
etc.
Use the formula =INDIRECT($A1 & "!G850") and copy that down column 1. For other columns you use the respective cell reference.
You can make it a bit more dynamic to include a row at the top in which you specify the exact cell reference to use in the formula for each column.
The formula should then read something like =INDIRECT($A1 & "!" & B$1)
This will allow you to simply copy the same formula to all cells and it will use the sheet name from the first column and the cell reference at the top to lookup the correct cell from the correct worksheet

Loop and compare values from array

In Sheet1 I have a single column with populated cells from 1-20 row with regular numbers. Look at picture bellow:
In Sheet2 I have also a single column, cells are starting from 5-25. If I enter some values into these cells, in Sheet1 from cell with that same value to column "D" background color is changed. Look at pictures bellow to see how it works:
I'm doing it with this piece of code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row >= 5 Then
If Target.Offset(0, 0).Text <> "" Then
Dim n As Long
For n = 5 To 25
If Target.Offset(0, 0).Value = Worksheets("Sheet1").Range("A" & n).Value Then
Worksheets("Sheet1").Range("A" & n & ":D" & n).Interior.ColorIndex = 3
End If
Next n
End If
End If
End Sub
Now, I'd like to make some kind of check every time Sheet1 is activated, in a way if there are no values in cells Interior.ColorIndex = xlNone for all the cells in Range("A1:A20"), if there is a value in some cells Interior.ColorIndex = 3 for those cells. I was thinking about to put these values into an array and then loop through it to compare values but I'm new to VBA so help would be welcome. If there is a better solution, just bring it on.
Also, I'd like to make a piece of code for a situation if I replace value 12 with 17 that Interior.ColorIndex of cell that contains 12 goes to xlNone and of 17 Interior.ColorIndex goes to "3".
So, every suggestion is welcome.
No VBA is needed, as pnuts says.
The easiest way to do this with the colours is with Conditonal Formatting using Formula to check the value of the cells in column A on one sheet against the values in the rows where you want the colour to change and apply the formatting.
See:
MSDN Office Online: Use a formula to apply conditional formatting
Contextures.com: Excel Conditional Formatting -- Examples
Chip Pearson Excel MVP: Conditional Formatting
J-Walk Mr Spreadsheet: Conditional Formatting
BUT if you want VBA, then you can do this in the workbook and worksheet event handlers.
Worksheet Selection/Activation:
in Excel on Sheet1, right-click on the sheetname at the bottom, and click View Code. This will open the class module for Sheet1 in the VB Editor.
At the top of the code module on the left, select Worksheet from the drop-down, and on the right drop-down, click the Activate event-handler.
This will create an empty sub-routine that will be executed by Excel everytime that you select the Sheet1 worksheet.
In that code you can make your checks.
Cell changes on sheet2:
To get code to run everytime you make a cell change on sheet2, you need to open the class module for sheet2, select Worksheet from the drop-down on the left, and Change for the event.
This code will run everytime you change a cell on sheet2 and in here, you would write code that first checks if the Target argument is in your range like this:
If not Application.Intersect(Target, "A5:25") Then Exit Sub
Next you want to write your code to check if the value is no longer matching, and reset the colours.
HTH
Philip

Resources