Index, Match and Address functions in a formula but how do incorporate a certain condition to extract only certain data? - vba

My Workbook has three sheets: "Wire Sheet", "Paste Data" sheet and "Wire instructions"
I need the "Wire sheet to dynamically populate with the data from the other two sheets based on certain conditions, i.e. date and data from that date.
I am using the index, match address functions to find the names from the "paste data" tab based on a specific but I can't figure out how to put a condition in there to only return names that are "buys"...
Here are my formulas:
This is just to find the cell:
S17= =MAX(IF('Paste Data'!B:B = 'Wire Sheet'!K2, ROW('Paste Data'!B:B) - ROW(INDEX('Paste Data'!B:B,1,1))+1))
S18= =ADDRESS(MATCH(K2,'Paste Data'!B:B,0),2,3,1,"Paste Data")&":"&ADDRESS(S17,5,3,1)
S19= =INDEX(S18,1)
here is the formula i am using to return the data:
=IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4))
Example on how spreadsheet works:
Currently: if you place a specific date in cell K2 on the "wire sheet", the boxes (cells A18:O67) populate with the data from the other two sheets based on that specific date. The data coded "Sell" is being populated in the boxes on the wire sheet, but should not be.. here is an example:
For example: If you place the date 7/13/2018 in K2 cell, the cell B57 is populated with letters SCR, which shouldn't be the case, as if you go to the "paste data" sheet, this is a "sell".
enter image description here
Then if you place the date 7/16/2018 in K2 Cell -- the cell B18 is doing the same thing, its populated with WQ when it shouldn't be, as it is a "sell", on the "paste Data" sheet. I would like it to just skip over this row of data and go and find the next row that is coded "buy"..
enter image description here
I just want to place the data that are "buys", on the wire sheet. All the sells should be passed over. I am not sure how else to explain this, which might be part of the issue.
enter image description here
Thanks in advance.
https://my.pcloud.com/publink/show?code=XZNzcB7ZpIigcTAabUz2vpPaXQ4nSVUfdc2X

+-----[editRevision2]----+
My way :
Y5 =COUNTIF('Paste Data'!B:B,'Wire Sheet'!K2)
Z6 =IF((ROW(Z6)-5)<=Y$5,ROW(Z6)-5,"")
AA6 =INDEX('Paste Data'!F:F,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1,1)
AB6 =IF(AA6="Buy",AB5+1,AB5)
AC6 =IF(AA6="Buy",INDEX('Paste Data'!E:E,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1),"")
AD6 =IF(AA6="Buy",INDEX('Paste Data'!K:K,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1),"")
select Z6:AD6 and extend to D15, then
B18 =IFERROR(INDEX($AC:$AC,MATCH(A18,$AB:$AB,0)),"")
E19 =IFERROR(INDEX($AD:$AD,MATCH(A18,$AB:$AB,0)),"")
copy B18 to J18, B31, J31 ...
and copy E20 to J20, B33, J33 ...
+-----[ProviousEdit]----+
Make
B18 =if(SUMIFS('Paste Data'!$K:$K,'Paste Data'!$E:$E,IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4)),'Paste Data'!$B:$B,$K$2,'Paste Data'!$F:$F,"Buy")=0,"",IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4)))
and adjust the INDEX(INDIRECT(S19),1,4) accordingly for J18,B31,J31 ...
Hope that solves.. (:

Related

Find a match on a different sheet then replace a cell in that row

I'm not a VBA expert so struggling to get this to work by recording macros investigation - I currently have no macro I'm working off as the one I tried seems to delete random cells
I have a range of data:
Column A-P and rows 5-54, in Sheet 1
I have two values in sheet 2, the search ID (C2) and the new input (F2)
I'd like to search Sheet 1 column A for the search ID (sheet 2, C2) then replace the value in column P of that row with the value in Sheet 2 F2.
The use of this is on a register of items that I want to change as on or off site (the register is sheet 1), the ID of the item that is moved is put in Sheet 2 C2, then F2 uses =vlookup to show the current status of the item, this is then changed using a drop down box and I'd like this update to be copied over to the old register to update it.
The rest of the formula would be to clear the change of location form and repopulate the vlookup into the F2 cell:
Sheets("Sheet 2").Select
Range("C2").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = "HPC-RS-"
Range("F2").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(R2C3,'Sheet 1'!R5C1:R54C16,15,FALSE),"""")"
Your "delete random cells" comment leads me to beleive that maybe you're not intentionally using R1C1 relative cell notation in your code, as opposed to "standard/absolute" A1 notation.
For example, Range(F2) refers to the cell at the intersection of column F and row 2, whereas R4C2 refers to the cell 4 rows down and 2 columns to the right of "whatever cell is currently active".
Before recording a macro, you can enable/disable relative references with a button near the "record macro" button. (I'm on my phone so I can't double check the button...)
A relative reference in an Excel macro means relative to the currently active cell. So use caution with your active cell choice — both when you record the relative reference macro and when you run it.
This page walks you through creating a demo of both types of macros: https://www.dummies.com/software/microsoft-office/excel/recording-excel-macros-with-relative-references/

Comparing 2 excel sheets and returning a data

I'm trying to compare two Excel sheets, Sheet1 column O to Sheet2 column A:M, if it found a match, it will copy Sheet 2 "down cell of matched data" (ie match data A3, copy A4) then paste to Sheet 1 column R. I'm (very) new to VBA and Macros so I don't know how to do this. Thanks in advance!
In sheet 1 of column O - datas are USD,JPY,TWD, etc. In sheet 2 column A to M, a specified exchange rate per currency. If sheet 1 column O data is USD, it will search in Sheet 2 with matching "USD"; if cell A3's data is USD, the exchange rate is in cell A4 which will be copied and pasted into column R of Sheet 1 corresponding to the row of USD.
So what I'm dealing with is something kind of like this:
This is what I’m looking for after the macro
Since Sheet 1’s cell O1 matches Sheet 2’s cell A3, I want it to return Sheet 2’s cell A4’ s value and paste it to corresponding row of Sheet 1’s cell R1.
Let me know if this makes sense or if you need further clarification.
Thanks!
Most of the code you need you can manage by yourself using macro recorder:
Start recording new macro
Select cell O1
Copy selected cell (by pressing RMB or ctrl+C)
Go to Sheet2
Select your data (A3:M7) with mouse
Press ctrl+F to open "Find" window
Paste value of copied cell
Press Enter. Cell with searched value should be selected
Press down arrow to move selection one cell down
Copy value from selected cell
Go to Sheet1
Press right arrow to move to column R
Paste copied value
Stop recording the macro
After that you need to find how to use For loops and add it to your code. Good luck!

How can i compare the data from a sheet to another?

As I have some columns with data in sheet 1 & the same column with approx. same data except some in sheet2 .So I want to compare the data from sheet1 to sheet2 & it should show something what will be easy that data is "Differ" on those cells from sheet1 to sheet2 .
By anyway I want to know where the data are different.
Lets assume your first sheet is Sheet1 and the 2nd is Sheet2,
Go to the cell a1 on Sheet2 and on home ribbon select conditional formatting -> highlight cells rules -> equal to -> and on the open window, enter the formula:
='Sheet1'!A1
press apply.
Now use the format painter brush when you are on the same cell on select all the range you have.
you can choose the color you wish to distinguish between the equal cells with non equal cells on the 'with' on the opened window

macro code to show much input range in dropdown list

I need a macro code to display more than one input range in dropodown list that I created in sheet2 via the form control.
I want an event with IF logic, where I have many names range from another sheet with the name eg: DaftarA (in sheet1 C1:C30), DaftarB (in sheet1 C40:C60), DaftarC (in sheet1 C70:C90).
How to write macros if the value in sheet2 C1 1, the dropdown list will display the input range of (name range) DaftarA, if the value is 2 then displayed in the dropdown list is (name range) dDftarB and so on ..
is there anything that can help? thank you
You can define a name for the list through the offset formula and use that name as a list for data validation drop down box.
=OFFSET(Sheet1!$B$1,Sheet1!$F$1,0,Sheet1!$E$1,1)
where cell B1 is top of the list, cell F1 shows how much you offset down, cell E1 will control the length of the list. It will work however only if your multiple ranges are on the same sheet and in the same column
It will also work if you define a name with the following formula
=IF(Sheet1!$F$1=1,test1,IF(Sheet1!$F$1=2,test2,IF(Sheet1!$F$1=3,test3)))
However in this case you need to name each particular range you want(like in this example test1, test2, test3) and of course you can't put too many nested formulas as it will get messy.

Insert row with data into excel sheet from another sheet dynamically

I have two different excel sheet first sheet contain some country list and second sheet is blank. There is a dropdown column with every country which contain 'Yes' 'No'. When I select yes I want that, the selected country row will automatically add to second sheet with all data. When I select more country they will dynamically insert/add to second sheet with maintaining country order in the first sheet.
These can be done with macro but I want to do this with formula.
Try this:
=IFERROR(INDEX(Sheet1!$A$1:$C$7,SMALL(IF(Sheet1!$D$1:$D$7="Yes",ROW(Sheet1!$D$1:$D$7),1E+99),ROW($A1)),COLUMN(A$1)),"")
Input formula in Cell A2 of Sheet2 and press Ctrl+Shift+Enter.
Then copy to remaining cells. Adjust the addresses in the formula to suit. HTH
Result: