I am a newbie with VBA and would like to perfect the last step in a complex spreadsheet. I hope someone can help me.
I need to convert EUR to USD based on historical dates which are to be found in adjacent cells and I need to do this for an entire column.
My query works fine with a fixed date inserted, no variable. How can I run this type of query with VBA for each row while inserting the appropriate variable date?
I have column B with date, column R with a modified date and column S with EUR value.
My target cell would be something like the below formula, where I have inserted in brackets where I need the variables applied to the search query. (dates).
Basically: If B5 is empty- do nothing, if R5(modified date) is empty- use B5 date for search, or else use R5 date for search
=IF( B5="", "", IF(R5="",[QUERY DATE VALUE IS B5] S5*XCH!B2, [QUERY DATE VALUE IS R5] B5*XCH!B2))
Sorry if I am not very technical here, thus I'm including all the info I have.
My working query (not VBA) is set up like this: (Note Date in query)
APPLIED STEPS:
Source: = Web.Page(Web.Contents("https://www.x-rates.com/historical/?from=EUR&amount=1&date=2018-07-01"))
Navigation: = Source{0}[Data]
Changed Type: = Table.TransformColumnTypes(Data,{{"Euro", type text}, {"1.00 EUR", type number}, {"inv. 1.00 EUR", type number}})
Removed Bottom Rows: = Table.RemoveLastN(#"Changed Type",8)
For example, in my target cell, the simple formula below works by using the fixed date inserted into the query (not the appropriate date).
=IF( B5="", "", IF(R5="", S5*XCH!B2, S5*XCH!B2))
Now, how do I get the above results for each cell BUT based on the values in R5 and S5 respectively?
Is this even possible to run VBA for each single cell in a column? All data is currently imported via a Macro from another worksheet. No user input.
So I would either use a macro- button to update all values on click, or use VBA to update the EUR value the moment data is imported.
I greatly appreciate any help I can get.
Related
Am hoping I can get some help with a VBA code sample to look up specific values in multiple columns (4 to be exact) and populate a specific text in another column (outside of the first 4). This is all happening within 1 single worksheet. See below for 4 criteria and specified verbiage to be populated:
column 1 value: "Yes"
column 2 value: "Yes"
column 3 value: "R" or "S"
column 4 value: Begins with "9" or "88"
IF all criteria are met, then populate "AWP Review".
I use my excel in spanish, but I'll try to translate the fomula
I guess you can write this formula to filter and copy and paste later
other way would be record a macro, filtering from left to right using your criteria
if I have a wrong idea let me know
=SI(SUMA(CONTAR.SI.CONJUNTO(A2,"YES",B2,"YES"),SI(O(C2="R",C2="S"),1,0),SI(O(D2=9,D2=88),1,0))=3,"SOME TEXT","")
=IF(SUM(COUNT.IFS(A2,"YES",B2,"YES"),IF(OR(C2="R",C2="S"),1,0),IF(OR(D2=9,D2=88),1,0))=3,"SOME TEXT","")
I have got an Excel spreadsheet. This spreadsheet has just one tab in it. The Tab name is dynamic in nature and changes every week also the number of rows.
I have column A filtered already with a VBA macro. A1 has the header.
Now, I wanna find how many rows are there in this already filtered column A.
I am looking for any VBA function.
I have tried using Subtotal function.
=Subtotal(103,A2:A1345)
But I don't know the end range. As of now the end range is A1345. It will change every time in future if the new rows are added.
I tried multiple things but those did not work. I am quite new to VBA.
If A1 will never be blank, you could use (in a column other than A)
=Subtotal(103,A:A)-1.
Or, if there will be data below your table not to be counted, then format your table as a Table and use structured references (and this formula could go into column A)
=SUBTOTAL(103,Table1[column_header])
You can put the formula in column A if you use another column's last populated cell as the demarcation point.
If column B contains numbers then,
=subtotal(103, a2:index(a:a, match(1e99, b:b)))
If column B contains text then,
=subtotal(103, a2:index(a:a, match("zzz", b:b)))
I have the following array formula which works for what I want to do but I'm trying to change the formula when a user selects a value.
=INDEX($A$2:$B$70,SMALL(IF($A$2:$B$70=$A$121,ROW($A$2:$B$70)),ROW(1:1))-1,1)
It's used for a monthly report and the user will choose from a drop down the day of the month, e.g 1,2,3 - 31.
So if the user selects 1 from the drop down menu I want the formula to use the above formula.
If they select 2 for example I want the formula to move over a column so it would change to
=INDEX($A$2:$C$70,SMALL(IF($A$2:$C$70=$A$121,ROW($A$2:$C$70)),ROW(1:1))-1,1)
and so on moving over a column at a time.
It this possible at all or can it even be done without VBA?
I have an example of what I want done on the following link
https://docs.google.com/spreadsheets/d/1MDOzoQxYLgW-UOyljZsMwSu8zyAB7O2k1V-bTNP5_F0/edit?usp=sharing
All the data is on the first tab called staff. Each employee has a row and the duty assigned under the corresponding day column.
On the Roster tab it summarises each day. So what I am trying to get to happen is when you choose the day of the month (or preferably the actual date) the sheet changes to reflect the data.
At the moment the code I have working does for just Day 1 because the column references are coded into the formula. I was hoping to somehow choose 6 for example from the drop down and then the formula will map chosen day to the corresponding range in the raw data and update the formula and change the formula from Staff!$A$2:$B$68 to Staff!$A$2:$G$68.
If the formula finds no more entries if shows #NUM! but I intended to use the function ISERROR() to replace #NUM! with "".
This is what I'm trying to achieve it if makes sense?
There are a few issues here/ You are returning the value from column A so the first range can be $A$2:$A$70 and that means you don't need the 1 to specify the column_num. The IF statement was covering A2:C70 when you really only want either B2:70 or C2:C70 depending on the 1 or 2.
Assuming that A122 has either a 1 or 2 in it then,
=INDEX($A$2:$A$70, SMALL(IF(INDEX($B$2:$C$70, 0, $A$122) = $A$121, ROW($1:$69)), ROW(1:1)))
Standard non-array alternative,
=INDEX($A$2:$A$70, SMALL(INDEX(ROW($1:$69)+(INDEX($B$2:$C$70, 0, $A$122) <> $A$121)*1E+99,, ), ROW(1:1)))
I have a spreadsheet worksheet called “ISO Procedure Master List” where the date a procedure is requested is in column G (Format m/dd/yyyy).
In column H the date the procedure is completed is entered. Column H uses the same date format but may contain blanks (procedure not completed yet).
There are currently 67 rows of information in the spreadsheet that span from 2011 to 2015 and that number will continue to grow.
QUESTION, I would like to get the average time (in days) it took from a procedure request (column G) to the completion of procedure (column H) for all of the procedures requested in a given year.
In other words the average (in days) time it took to complete procedures in a given year.
This answer will be in a cell C34 in the same workbook but a different worksheet called “ISO Matrix”. (This information probably does not matter but I thought I would add I just in case)
I have tried several Sumproduct variations with no success.
Assumptions:
Dates in columns G and H are dates, not text string,
Data start in row 2, using row 1 for headings.
For convenience, I assume you have named the ranges you wish to average requestDate and completeDate
You wish do ommit the rows where the procedure is not finished from the average calculation.
After naming your ranges, input the following formula into C34 on "ISO Matrix" tab:
=AVERAGE(IF(completeDate<>"";completeDate-requestDate))
This is an array formula, so when normally pressing enter, remember to press CTRL+SHIFT+ENTER instead. When highlighting the cell, it will then look like this:
{=AVERAGE(IF(completeDate<>"";completeDate-requestDate))}
NOTE: My language pack uses ; as formula separator, so if you language uses , instead, change the formula to:
=AVERAGE(IF(completeDate<>"",completeDate-requestDate))
EDIT: So, I didn't catch that you needed to average by year. In line with my recent formula, it could be update to suit your request.
=AVERAGE(IF(completeDate<>"";IF(YEAR(requestDate)=A15;completeDate-requestDate)))
where A15 holds the year you are interested in. I tried it with an AND in the first IF instead of two IFs, but that did not seem to work. Mind you, you might still need to change ; to , and you also need CTRL+SHIFT+ENTER for this one.
You could also add the code below, to handle the case where you test a year that is not present in the list:
=IFERROR(AVERAGE(IF(completeDate<>"";IF(YEAR(requestDate)=A15;completeDate-requestDate)));"No such year")
...or something like that
I have an excel with two sheets named raw and data here
raw sheet :
date sheet :
In raw sheet I will be uploading data manually.
What I am looking for :
In this, I want to create a formula which will check each name from the data sheet in raw sheet and it has to pick the total value (D column in raw) and update the same in data sheet in a cell which matches with last modified date.
For example :
Name is R420864561 and its last modified date is 20141201 and total value is 10.
So in my data sheet, it has to be updated like this
Above, value 10 is updated in a cell which matches the last modified from raw sheet with date in data sheet, here both are 20141201.
I am using below formula for this (formula in C3)
=SUMIFS(raw!$D:$D,raw!$A:$A,$A3,raw!$C:$C,C$2)
Now, if last modified date 20141202 with total 50
Now, data sheet will updated like below using above formula
What I need now :
In above, if I update value in another date, the data updated in previous date is getting changing to 0. But I need to keep that data in that cell, if there is no update in that.
In above case, I need to keep previous data (for date 2014201)10 in data sheet cell C3, and update 50 in D3 (for date 20141202)
I have added below code with macro, to copy paste the formula value, as simple value
Dim rngCell As Range
For Each rngCell In ActiveWindow.RangeSelection
rngCell.Value = rngCell.Value
Next rngCell
But that is not working here, It still resetting previous value to 0 when I update for a different date.
Any suggestion to correct this is much appreciated
I have uploaded the copy of the excel which I am working in below location :
https://www.dropbox.com/s/jpubzqbco5mflu5/1.1_test.xlsm?dl=0
This should work assuming your loop is correct.
rngCell.Copy
rngCell.PasteSpecial Paste:=xlPasteValues
Try For Each rngCell In Application.Selection to start the loop
you VBA is wrong:
update it using this one:
Sub saveMyData()
Set ws = ActiveSheet
ws.Range("C3:E999").Copy
ws.Range("C3").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("C3").Formula = "=SUMIFS(raw!$D:$D,raw!$A:$A,$A3,raw!$C:$C,C$2)"
Range("D3").Formula = "=SUMIFS(raw!$D:$D,raw!$A:$A,$A3,raw!$C:$C,D$2)"
Range("E3").Formula = "=SUMIFS(raw!$D:$D,raw!$A:$A,$A3,raw!$C:$C,E$2)"
End Sub
Here is ***UPDATED***the example sheet to try and see if it works.
it was because your VBA code was mixed up with unncessary codes.
From all appearances, the problem is with how you are presenting the question and plan to use the raw spreadsheet. From the information provided, it seems like you plan on entering records in raw, but then you also intend to change them. Also, based on your example and how you are describing the problem, it's not clear why you are using SUMIFS rather than INDEX(MATCH).
It would seem that your raw spreadsheet should have multiple records, one for each Name/Last Modified combination, and more than one for each combination to necessitate the use of SUMIFS. Then your formula in data will pick up the relevant info in raw.
If you plan on only having one entry for each Name in raw, and changing the last modified date and the total in raw it seems rather pointless to have separate spreadsheets at all, just enter it into data in the first place under the respective last modified date.