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
Related
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
In excel I have a bunch of columns that are made up of a sequence of 1s and 0s. For each column I am looking to count the number of times that there are 4 or more 1s consecutive 1s in that column. I believe that a piece of vba code would be the easiest way to do this?
Example:
0
1
1
1
1
0
1
1
1
1
1
0
0
The count here would be 2.
Thanks for any help.
use this function:
Function Count1s(rng As Range) As Long
Dim rArr() As Variant
Dim i As Long
Dim t As Long
Dim n As Long
t = 0
rArr = rng.Value
For i = 1 To UBound(rArr, 1)
If rArr(i, 1) <> 1 Then
If t + 4 <= i Then
n = n + 1
End If
t = i
End If
Next i
Count1s = n
End Function
You would call it as a regular formula:
=Count1s(A1:A12)
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 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 7 years ago.
Improve this question
I have a table below with details in column A and B. I want to search a string in C from A and paste value of Column B in Column D with help of VBA.
Example:-
A B C D
STRAT Strategy s_strat_nhnh Strategy
TRDMK Trademarks bng_trdm_ndnd Trademarks
TRDMK not in bng_trdm_ndnd.
But if I got it right, you want something like
Then Code is:
Sub Test()
CStartRow = 1
CEndRow = 5
AStartRow = 1
AEndRow = 3
For I = CStartRow To CEndRow
For J = AStartRow To AEndRow
If InStr(UCase(Range("C" + CStr(I))), UCase(Range("A" + CStr(J)))) Then
Range("D" + CStr(I)) = Range("B" + CStr(J))
Exit For
End If
Next J
Next I
End Sub
If you do not want to use VBA then you can use this formula.
Formula in d1 cell is:
=IF(ISNUMBER(SEARCH(A1,C1)),B1,"")
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
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)