How to stop Excel from changing referenced cell range - excel

My formula in Sheet 1, A3 is
=SUMPRODUCT(('count May'!$D$2:$D$2000=Categories!$A$5)*('count May'!$E$2:$E$2000=Categories!$B$3)*(ISNUMBER(SEARCH('count May'!$F$2:$F$2000,Categories!$C$4))))
Count may is the sheet for the month of may(I'm doing this for a full year), categories is the sheet that has my helper table. When I paste the data from the export with about 1600 rows one column with different companies, another column with different employment status,another column with various locations i.e company $A$5, fulltime $B$3, Location $C$4 into any month sheet the cell that has the above formula changes all the cell ranges from $2:$2000 to $1609:$2000.
=SUMPRODUCT(('count May'!$D$1609:$D$2000=Categories!$A$5)*('count May'!$E$1609:$E$2000=Categories!$B$3)*(ISNUMBER(SEARCH('count May'!$F$1609:$F$2000,Categories!$C$4))))
I then get #Value! or #N/A in A3. Essentially the pasted data makes the formula range in A3 start from a few rows after the last pasted data cell. I have tried to change $D$1609:$D$2000 to $D:$D, $E:$E, $F:$F, but I get a excel cannot complete this task error, I tried changing $D$2000 to $D$1600 but that didn't work and is not feasible because every month will have a different number of rows. I tried cut instead of copy but still happens.
If it is any help the data is put together in one sheet, column D,E,F and then I copy or cut and paste in the month sheet and then the formulas are in a different sheet but reference each month.
Any help is much appreciated.

I'm joining in late here so may be you may have already fixed your bug (if it's the case lets know how!).
If I understand correctly, you have sheet 'Count May' with a formula in A3 and you're a copying data (range A1:F1600) into 'Count May' (presumably in A2) in order to use your formula. Doing so messes up the reference in the formula in A3.
The only way I was able to recreate this was by copying/pasting entire rows, (i.e. rows 1:1600), instead of the range of cells needed, (i.e. A1:F1600). That would insert 1600 rows in 'Count May' and effectively push your reference down. Your second reference wouldn't get moved because it references to another sheet, 'Categories' untouched by the copy/paste. Your problem should be fixed by copying the range of cell needed (instead of entire rows) and selecting A2 (not row 2) to paste.

Related

Cleaning a column from one sheet into another

Sorry if the title is off, but I have no way of making this short.
I have an excel file with 2 sheets: Sheet1 has the first column filled with data, but in a random pattern (ex: 6 consecutive cells are with data, 6 are without, other of the following alternate; basically there is no way of knowing if the next cell has data or not). I want to copy the first column from Sheet1 into Sheet2 without any blank cells or duplicate ones (the order of the data can be maintained or be changed as the result of the formula).
Can this be done without any coding?
Assuming your Sheet1 is as follows
Then in Cell A2 of Sheet2 enter the following formula
=IFERROR(INDEX(Sheet1!A$2:A$50,SMALL(INDEX(NOT(ISBLANK(Sheet1!$A$2:$A$50))*ROW($A$1:$A$49),0),COUNTBLANK(Sheet1!$A$2:$A$50)+ROW($A1))),"")
Drag/Copy down as required. Change range in formula as needed. See image for reference.
EDIT :
To get unique values from Column A of Sheet2 enter below formula in Cell B2 of Sheet2
=IFERROR(INDEX($A$2:$A$20,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$20),0,0),0)),"")

Exce: VB command to copy a range of cells from one sheet to another sheet

I have 2 sheets (calculator & backupschedule) in the same file and i am transferring data to and fro between the sheets.
I am having trouble figuring out how to transfer a range of cells from the calculator sheet to the other.
My current VB code is :
Sheets("Calculator").Range("R3:R15").Copy Destination:=Sheets("BackupSchedule").Range("E8:E20")
but i get an #REF! error in the backupschedule sheet in the cells E8:E20.
I want to copy the cells in Column R, Row 3 through 15 (Cells: R3,R4,R5,etc) and then place them in column E rows 8 through 20 (Cells: E8,E9,E10, etc)
Can someone give me a hand with this please?
You are getting the #Ref because you are copying formulas with references that when pasted in an earlier column are off the sheet relative to where you are pasting it.
If I have a formula in C4 of =A1 if I copy and paste that in D5 it will become =B2. If I try to paste the copy in B3, the reference is no longer valid as it now is trying to refer to a cell that is off the sheet.
I suspect you only want the values at this point. There are a few methods to get the values into the desired cells.
You can copy and paste just the values:
Sheets("Calculator").Range("R3:R15").Copy
Sheets("BackupSchedule").Range("E8:E20").PasteSpecial xlValues
You can assign the values directly(Recommended)
Sheets("BackupSchedule").Range("E8:E20").Value = Sheets("Calculator").Range("R3:R15").Value
Or you can put formulas in the range that refer to the original:
Sheets("BackupSchedule").Range("E8:E20").Formula = "=Calculator!R3"

Excel function that copies rows if they fall within the range of 2 dates

So at the top of my Excel sheet I have 2 cells, A2 and B2, where people can enter a starting and ending date.
On a seperate sheet I have an enormous list of starting and ending dates in columns A and B, and corresponding data for each of these 'events' in columns D through G. I need my function to copy all rows where the starting date falls between the two specified dates, and copy the data to the first sheet, in cells A4 - G4 through A100 - G100. (I just chose 100 as a large number, to make sure the area where the data gets placed is large enough)
I'm guessing this function I need includes the INDEX function, but I only know how to use it to look up one data cell at a time, not how to copy an entire range of cells.
Can anyone help?
No helper columns required.
Enter this formula into cell A4:
=IFERROR(INDEX(data!D$2:D$9999,SMALL(IF((data!$A$2:$A$9999>=$A$2)*(data!$A$2:$A$9999<=$B$2),ROW(data!$D$2:$D$9999),9E+99),ROW(1:1))-1),"")
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Now copy the formula to the range B4:D4.
Now copy the A4:D4 to the range A5:D100.
That's it.
Let's say Column C in the data sheet is blank, and free to add a formula.
Let's also assume that the data begins in row 2.
Then the following formula can be put in C2 & copied down:
=IF(AND(A2>=Sheet1!$A$2,B2<=Sheet1!$B$2),C1+1,C1)
Basically it is saying that if the beginning date of the current record is greater than or equal to the date the user is looking for, and the ending date is likewise within range, iterate the record, otherwise not.
At this point the user sheet can have a simple VlookUp as follows:
In D1: =VLOOKUP(ROW($A1),Sheet2!$C:$G,COLUMN(B$1),0)
Copy this across to G and down however many rows you like.

Excel formula to pull data from last 5 rows of a cell range that has new rows added daily

As the title suggests, I have a worksheet (sheet1) that has lots of data that spans columns A-E and with rows that are added daily, What I want to do is on a separate worksheet (sheet2) show the data from the last 5 rows of sheet1.
Providing there is continuous data within column A on Sheet1, you could also use the INDIRECT() and COUNTA() functions.
=INDIRECT("Sheet1!$A$"&COUNTA(Sheet1!$A:$A)-4)
=INDIRECT("Sheet1!$A$"&COUNTA(Sheet1!$A:$A)-3)
=INDIRECT("Sheet1!$A$"&COUNTA(Sheet1!$A:$A)-2)
=INDIRECT("Sheet1!$A$"&COUNTA(Sheet1!$A:$A)-1)
=INDIRECT("Sheet1!$A$"&COUNTA(Sheet1!$A:$A))
You would need to amend the column letter within the INDIRECT function for each column of data which you wish to view on Sheet2.
In an appropriate cell on Sheet2, use this formula,
=INDEX(Sheet1!A:A, MATCH(1E+99, Sheet1!$A:$A)-(ROW(1:1)-1))
Fill right for a total of 5 columns then fill those 5 cells down 5 rows.
That formula will find the last number in a column. This is often the case as the left-most column mat hold an ID number. The same reference point should be used to collect cell values from other columns to avoid the confusion that a rogue blank cell would create.
If all you have are text values then the formula in the first cell would be,
=INDEX(Sheet1!A:A, MATCH("žžž", Sheet1!$A:$A)-(ROW(1:1)-1))
Fill right and down as described above.

Merge two Excel tables Based on matching data in Columns

I've been working on a excel problem, that I need to find an answer for I'll explain it below.
I've Table01 with the Columns :
Group No
Name
Price
I've Table02 with the columns:
Group No
City
Code
I've merged two tables of Table01 & Table02 as shown in the Image03 , But without order.
But,as you see Group No Column is similar in both tables.
What I need is to get the matching rows of Table01 & 02 considering 'Group No' Column.
The Final result is to be seen as the final image.
Is there a way to do this with excel functions ?
Thank You!
Put the table in the second image on Sheet2, columns D to F.
In Sheet1, cell D2 use the formula
=iferror(vlookup($A2,Sheet2!$D$1:$F$100,column(A1),false),"")
copy across and down.
Edit: here is a picture. The data is in two sheets. On Sheet1, enter the formula into cell D2. Then copy the formula across to F2 and then down as many rows as you need.
Teylyn's answer worked great for me, but I had to modify it a bit to get proper results. I want to provide an extended explanation for whoever would need it.
My setup was as follows:
Sheet1: full data of 2014
Sheet2: updated rows for 2015 in A1:D50,
sorted by first column
Sheet3: merged rows
My data does not have a header row
I put the following formula in cell A1 of Sheet3:
=iferror(vlookup(Sheet1!A$1;Sheet2!$A$1:$D$50;column(A1);false);Sheet1!A1)
Read this as follows: Take the value of the first column in Sheet1 (old data). Look up in Sheet2 (updated rows). If present, output the value from the indicated column in Sheet2. On error, output the value for the current column of Sheet1.
Notes:
In my version of the formula, ";" is used as parameter separator instead of ",". That is because I am located in Europe and we use the "," as decimal separator. Change ";" back to "," if you live in a country where "." is the decimal separator.
A$1: means always take column 1 when copying the formula to a cell in a different column. $A$1 means: always take the exact cell A1, even when copying the formula to a different row or column.
After pasting the formula in A1, I extended the range to columns B, C, etc., until the full width of my table was reached. Because of the $-signs used, this gives the following formula's in cells B1, C1, etc.:
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(B1);FALSE);'Sheet1'!B1)
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(C1);FALSE);'Sheet1'!C1)
and so forth. Note that the lookup is still done in the first column. This is because VLOOKUP needs the lookup data to be sorted on the column where the lookup is done. The output column is however the column where the formula is pasted.
Next, select a rectangle in Sheet 3 starting at A1 and having the size of the data in Sheet1 (same number of rows and columns). Press Ctrl-D to copy the formulas of the first row to all selected cells.
Cells A2, A3, etc. will get these formulas:
=IFERROR(VLOOKUP('Sheet1'!$A2;'Sheet2'!$A$1:$D$50;COLUMN(A2);FALSE);'Sheet1'!A2)
=IFERROR(VLOOKUP('Sheet1'!$A3;'Sheet2'!$A$1:$D$50;COLUMN(A3);FALSE);'Sheet1'!A3)
Because of the use of $-signs, the lookup area is constant, but input data is used from the current row.

Resources