Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am confused as how to create interest rate input as an argument
When I try to list Dim Rate as single an error box says duplicate argument
The purpose of this function is to calculate NPV for a set of cash flows (myarray)
Public Function myNPV(rate As Single, r As Range) As Single
Dim myArray(64) As Double
Dim i As Integer
Dim sum As Double
For i = 0 To n
Next i
For Each elem In r
myArray(i) = elem.Value
myArray(i) = myArray(i) / ((1 + rate / 100) ^ i)
i = i + 1
Next elem
End Function
n is zero. The For loop does nothing.
myNPV never gets assigned a value in the UDF
Related
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
How can I get random numbers generated by a log normal distribution in VBA?
I used
Dim upper As Double, lower As Double
' Declare 2 arrays
Dim irr(26) As Double
Dim lirr(26) As Double
' set the upper and lower band
upper = 0.125
lower = 0.02
...
lirr(i ) = WorksheetFunction.LogInv(Rand, (upper - lower), lower) + lower
However I get an error.
Option Base 1
Public Function LOGINV_SAMPLE(Optional n As Integer = 1, Optional md As Variant = 1, Optional stdv As Variant = 0) As Variant
'#Execute this as array formula i.e Cnt+Shft+Enter
Dim x(), i, p As Variant
ReDim Preserve x(n)
For i = 1 To n Step 1
Randomize
p = Rnd()
x(i) = Application.LogNorm_Inv(p, stdv, md)
Next i
LOGINV_SAMPLE = Application.Transpose(x)
End Function
This works.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
.
Hello guys,I need your inputs on the topic here.
I intend to combine or concatenate different value in different columns so its shown in a single cell.
Illustration is the following:
1:
Is it possible to do this without macro?
use
=CONCATENATE("The name of the painter: ",A3,CHAR(10), "The Hobby: ", B3, CHAR(10), "Tool used: ", C3,CHAR(10),"Remuneration: ", D3)
To answer your second question on how to do it with code:
Sub PopulateResultsToCell()
Dim X As Long, MyArr As Variant, PrefixArr As Variant
PrefixArr = Array("The name of the painter: ", "The Hobby: ", "Tool used: ", "Remuneration: ")
MyArr = Application.Transpose(Application.Transpose(Range("A3:D3"))) '<-- Change this for the range to read
For X = LBound(MyArr) To UBound(MyArr)
MyArr(X) = PrefixArr(X - 1) & Trim(MyArr(X)) 'Note: Option base is zero but transposing creates a base 1 array hence the X minus 1
Next
Range("F3").Formula = Join(MyArr, vbLf) '<-- Change this for where to populate the result to
End Sub
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I will write something like:
Dim Counter As Integer
Dim a As Integer
Counter = 0
a = 1
Counter-a
But, then VBA appends it to this:
Dim Counter As Integer
Dim a As Integer
Counter = 0
a = 1
Counter a '<---------------This change is what I am confused about
This is my full code so far:
Private Sub SpinButtonM_SpinDown()
Dim Counter As Integer
Dim a As Integer
a = 1
Counter a
UserForm2.Month.Caption = Counter
End Sub
You have to decrement like this:
Counter = Counter - a
If you want to subtract variable a from variable Counter then you need to store the result of that subtraction somewhere. So you might want to introduce another variable like
Dim result as Integer
...
result = Counter - a
msgbox(result)
Or maybe you want to decrease the Counter variable by a, then you need
Counter = Counter - a
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to subtract multiple values from the same number?
For example:
A = 1000
x = 200
y = 300
z = 400
In iteration 1: A - x = 800
In iteration 2: A - y = 500
In iteration 3: A - Z = 100
Can we assign a temporary variable to solve this problem? Also, I am looking to subtract all these values in a single cell that means the value should keep on changing in the single cell as follows A1: 800, A1: 500, A1: 100
This should get you started on your programming adventure:
Dim i As Long
Dim a As Double
Dim values As Variant
a = 1000
values = Array(200, 300, 400)
For i = LBound(values) To UBound(values)
a = a - values(i)
Range("A1") = a
MsgBox "Cell A1 now contains: " & Range("A1").Value
Next i
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am currently creating a chess game a to save me a large amount of if statements I was wondering if there is a way to insert a variable such as x into the label below:
Label1.Text = "MyRedPawns()"
I want it to go in the ( ) similar to what would be used for a Console.Writeline statement.
Edit:
Here is the code:
For x = 1 To 4
If mouseclicklocation.X >= MyRedPawns(x).getposition.X And mouseclicklocation.X <= MyRedPawns(x).getposition.X + 80 Then
If mouseclicklocation.Y >= MyRedPawns(x).getposition.Y And mouseclicklocation.Y <= MyRedPawns(x).getposition.Y + 80 Then
Label1.Text = "MyRedPawns( )"
Piecefound = True
End If
End If
Next x
I want the value of x which is in the for loop to be passed in to the label1.text inside the ()
You can do something like this:
Label1.Text = "MyRedPawns(" & x & ")"
The question is not clear. However, i'll give it a try. I guess you want to insert the value of a variable x into a string. You can use String.Format:
Dim pattern = "MyRedPawns({0})"
Dim xVariable As Int32 = 4711
Dim result = String.Format(pattern, xVariable)
Result: MyRedPawns(4711)
Have a look at the remarks section of MSDN to see how it works.
If we had a variable x = "Hello" to get the text from x into the label we would do:
Label1.Text = x
I'm not sure what MyRedPawns() actually does or returns so I could be wrong but if it is returning a String and takes a parameter then you should be able to do:
Label1.Text = MyRedPawns(x)