Dragging down Arrayformla - arrays

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

Related

How to get array with values into one column

In excel I have two columns (A and B) filled with text values and I want to get all the values from the two column into one column (C) and it needs to be dynamic
example:
Column A: {car, plane, boat}
Column B: {bike, motor}
Column C: {car, plane, boat, bike, motor}
I hope someone can help me!
use:
=QUERY(FLATTEN(A:C); "where Col1 is not null")
This will work in both Excel(any version) and Google Sheets: Put this in C1 and copy down till you have enough cells filled to capture both lists maximum lengths:
=INDEX(A:B,IF(ROW($ZZ1)>COUNTA(A:A),ROW($ZZ1)-COUNTA(A:A),ROW($ZZ1)),IF(ROW($ZZ1)>COUNTA(A:A),2,1))&""
With Office 365 Excel:
=LET(
rng1st,A:A,
rng2nd,B:B,
cnt1st,COUNTA(rng1st),
cnt2nd,COUNTA(rng2nd),
sq,SEQUENCE(cnt1st+cnt2nd),
INDEX(CHOOSE({1,2},rng1st,rng2nd),IF(sq>cnt1st,sq-cnt1st,sq),IF(sq>cnt1st,2,1)))
Put that in C1 and the results will spill automatically:
Google Sheets has a FLATTEN function which allows you to do this, but there is no equivalent function in Excel.
There is a workaround though, which does combines the 2 columns in the order of their rows:
This works in Excel Version 2019 or later
=FILTERXML("<a><b>"&TEXTJOIN("</b><b>",TRUE,A:B)&"</b></a>","//b")
=IF(SEQUENCE(ROWS(range1)+ROWS(range2))<ROWS(range1)+1,range1,INDEX(range2,MOD(SEQUENCE(ROWS(range1)+ROWS(range2),,ROWS(range2)-ROWS(range1)),ROWS(range2))+1,SEQUENCE(1,COLUMNS(range2))))
This will stack range2 under range1 in Excel (365) this also works for ranges with 2 columns, or more
If the amount of the rows won't be changed
=IFERROR(INDEX($A$1:$A$3, ROWS(C1:$C$1)), IFERROR(INDEX($B$1:$B$2, ROWS(C1:$C$1)-ROWS($A$1:$A$3)), ""))
ctrl + shift + enter
If the amount of the rows can be changed
=IFERROR(INDEX(INDIRECT("$A$1:$A$"&COUNTIF(A:A,"")), ROWS(C1:$C$1)), IFERROR(INDEX(INDIRECT("$B$1:$B$"&COUNTIF(B:B,"")), ROWS(C1:$C$1)-ROWS(INDIRECT("$A$1:$A$"&COUNTIF(A:A,"*")))), ""))
ctrl + shift + enter

Comparing two rows with array formula to indentify differences and return "Last Change Date"

I currently have an Excel Table which is edited by multiple users. I wrote some formula to compare the actual status with the last saved file. It works well, but as any array formula, it is extremely slow:
Macro copies all entries when I open the workbook (Mirror FEP Sheet)
Array Formula compares corresponding rows in the original Table and the Mirror Table to find any differences; if there was some modification, it returns TODAY(). If not, the previous date is written...
=IFERROR(IF(AND(EXACT([#[PTI-Nr]]:[#KIFA];INDIRECT("'Mirror FEP'!" & "B" & (2+MATCH([#[EAARCH-Nr]]; Table3[EAARCH-Nr]; 0))):INDIRECT("'Mirror FEP'!"&SUBSTITUTE(ADDRESS(1; COUNTA($2:$2);4); 1; "")&(2+MATCH([#[EAARCH-Nr]]; Table3[EAARCH-Nr]; 0))))); INDIRECT("'Mirror FEP'!" & "A" & (2+MATCH([#[EAARCH-Nr]]; Table3[EAARCH-Nr]; 0))); TODAY()); TODAY())
The formula is complex in order to find the right row in Mirror FEP even when the user changes the order of the original table.
I am familiar with the VBA solution, but my users need to Ctrl + Z all the time. Do you have any suggestion on how to speed up my Workbook? Alternative solutions are more than welcome!

Capture text from a column in another worksheet - Excel

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

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.

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