This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Refresh Excel VBA Function Results
I have simple function in excel:
Function Test() As String
Test = Now
End Function
and I am able to use it as:
Now why is it that when I press the button:
the value does not update !?
For example if I have a cell with the formula =Rand() every time I click the calculate value I will get a different number. How can I make my custom function behave the same way ?
Add application.volatile to the job
Btw, now() is available as an excel function
Related
This question already has answers here:
Python openpyxl data_only=True returning None
(7 answers)
Closed 1 year ago.
I am not able to print the computed cell value with this option. it is printing the formula instead of cell value.. can someone please help me on this.!!!!!!!!!!!!!!!!
sheet['L3'] = '=COUNTIF(B1:B431,"Resolved")'
now I want to print the L3 cell value to the screen
Python openpyxl data_only=True returning None
According the this thread, the formula needs to be evaluated by Excel before having its value cached.
This question already has answers here:
Replace characters in string with values
(3 answers)
Closed 3 years ago.
I'm trying to recall something from my brain from 6 years ago but I can't find it and the standard searches aren't bringing me joy.
I have a label like this:
Hello, this is my label and the value of the thing is: #value#. The label continues for a while here.
I need to update #value# in this instance with something from a database, however I can't remember how to without re-writing all the text again in the code. I know there's a way to do it, does anyone know this?
Thanks in advance!
If you are replacing existing text in the label, something like:
Dim myValueFromDatabase As String = "" ' Get the value from the database here
myLabel.Text = myLabel.Text.Replace("#value#", myValueFromDatabase)
Alternatively, you could use string interpolation:
Dim myValueFromDatabase As String = "" ' Get the value from the database here
myLabel.Text = $"Hello, this is my label and the value of the thing is: {myValueFromDatabase}. The label continues for a while here."
$"Hello, this is my label and the value of the thing is: {value}. The label continues for a while here."
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Files here
Hello,
I am trying to write code to format a report. The main issue with the report is that some cells store multiple pieces of data in a cell when each row should only have one piece of data in each cell. My solution thus far has been to use the text to columns function for the affected cells, paste all other data transposed, and finally copy and re-transpose the new data over the original report area. This has worked so far, but I am running into an issue with cells that store time. Cells with single times (such as 13:00) are in the custom format hh:mm, which vba converts to a a decimal number. Cells with multiple times (such as 11:009:008:0010:30) are viewed as a string.
The code I am currently using to split the times works for multiple time cells because it searches the string for ":", but vba does not detect the ":" in the custom format cell 13:00 since internally it sees that cells value as something like 0.56412.
I am kind of at a loss as to what to do here. I can't change the format that the report arrive to me in. My thought was that maybe I could find a way to turn the custom format "13:00" into a string "13:00" instead of 0.56412
I have attached the code file and the truncated dummy report I am testing to code on. I would like to thank everyone who responds for their help in advance!
to change a single time to a string, you can use format and identify the value to excel as a string using '
example:
'immediate window
[a1]="'"&format([a1],"hh:nn")
'or, using a range
range("A1")="'"&format(range("A1"),"hh:nn")
you can use isnumeric to check if it's a single time. True means it's a time, False means it's a string of times
I am having some problem with using a countifs formula in Excel / VBA. I have got the formula working perfect in Excel but ideally I want to use this in VBA with my form. Here is the formula in Excel which works a treat:
=COUNTIFS(Sheet1!A:A,"Place",Sheet1!K:K,"<"&TODAY())
will count the names places that are now in the past
=COUNTIFS(Sheet1!A:A,"place",Sheet1!K:K,">"&TODAY())
will count the names places that are current
I have five different Places in column A and hundreds of different dates in column K. The above formulas work well in Excel and return the correct values. I have spent hours trying to get this to work in VBA with my userform but keep getting various errors. The first part is not the problem but as soon as I get to the &today function it falls apart. From what I can see the &today function is not available in VBA and the &Date seems to be the recommendation. I have tried this but still get no where. I'm missing a trick (or several) here and I would really like to get this working in VBA rather than using the current formulas in Excel. The returned results are then displayed in textboxes on my form.
All ideas and feedback much welcome!
Second edit
================================
Thanks for the quick replies! Here is the actual code I am playing about with in VBA
'Count events by area'
Dim ListLondon As Long
ListLondon = .CountIf(Range("a1:a1998"), "London"), ("Sheet1!K1:K1998"), "<" & Date)
End With
Me.TextBox1 = ListLondon
I know the second part of the count if is all wrong regards the date - that's how I've left it for now. I am really hoping to use the current layout and a working Date / Today code at the end. Please show me what I've done wrong here!
====
oops - can see a mistake already - but the initial problem remains around the date issue. I should of used countifs as using multiple criteria.
You have to read the values of the cells to your VBA code. I recommend you to use Excel.Range object to do that. It can interpret the range like the edit line of the Excel, something like
Dim foo as Excel.Range
set foo = yourworksheet.Range("A1:B3")
Read the Date type data into VBA Date type variable by iterating through the cells.
Examine relation between the read data and the current date. Current date can be read by using the DateTime.Now function.
Increment a variable based on a decision
I'm new to VBA and have been reading all about user defined functions and macros. I'm hoping someone could help me out with a project.
I have a subscription to a service that pulls information into excel using an add-in in the ribbon. The only way to pull in the formula is to either 1) use the ribbon which involves a lot of clicking and waiting or 2)type in the formula into the cell with also takes times.
On excel, for normal functions (i.e. if, find, text), I often use the tab shortcut to fill out the formulas. I would like to to create a formula in excel (using VBA) so that I can write "=" -then hit tab - then reference a cell - and then the formula takes the referenced cell and returns a formula.
FYI - I am using Windows 7 and Office 2013
For example:
IF cell A1 the input number = 12345
In Cell B1 I enter the Comm formula that pulls in the data = "=ABC(A1,"Value_Name")
Cell B1 will display = ZYZYZYZY (which comes from the subscription database)
How do I write a VBA code that basically does:
Function (Value)
Returns =ABC(Value,"Value_Name")
: Which then calls the comm function and returns ZYZYZYZY
End Function
I tried my best to explain what I am trying to do - apologies if it was difficult to follow.
Thanks
You can call the other function using Application.Run:
Public Function MyUDF(Value As Variant) As Variant
MyUDF = Application.Run("ABC", Value, "Value_Name")
End Function