Bam_Mab91
09-09-2019, 02:03 PM
I am wanting to have my VBA compare to columns row by row. The row that has a greater value will have a 1 added and then print the result in a cell like a win - loss.
I only have one worksheet in this file. I am trying to compare cells B2:B18 to C2:C18.
This is what I have written so far:
Sub Record_Tracking()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim record As String
j = 0
k = 0
For i = 2 To 18
If [Worksheets(1).Cells(i,2).Value] > [Worksheets(1).Cells(i,3).Value] Then
j = j + 1
ElseIf [Worksheets(1).Cells(i,2).Value] < [Worksheets(1).Cells(i,3).Value] Then
k = k + 1
Else
j = j + 0
k = k + 0
End If
record = " - "
record = CStr(j) & record & CStr(k)
Next i
Worksheets(1).Range("B19").Value = "Record:"
Worksheets(1).Range("C19").Value = record
End Sub
When I click the button I have the macro on it does populate the cell but with 0-0. I am not used to super familiar with VBA, more with C and jython (used for ignition). Any tips would be great. I tried searching for topics and when through 3 to 4 pages before making the post because I didn't see what I needed. Sorry if this is a duplicate post.
Thanks in advance
I only have one worksheet in this file. I am trying to compare cells B2:B18 to C2:C18.
This is what I have written so far:
Sub Record_Tracking()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim record As String
j = 0
k = 0
For i = 2 To 18
If [Worksheets(1).Cells(i,2).Value] > [Worksheets(1).Cells(i,3).Value] Then
j = j + 1
ElseIf [Worksheets(1).Cells(i,2).Value] < [Worksheets(1).Cells(i,3).Value] Then
k = k + 1
Else
j = j + 0
k = k + 0
End If
record = " - "
record = CStr(j) & record & CStr(k)
Next i
Worksheets(1).Range("B19").Value = "Record:"
Worksheets(1).Range("C19").Value = record
End Sub
When I click the button I have the macro on it does populate the cell but with 0-0. I am not used to super familiar with VBA, more with C and jython (used for ignition). Any tips would be great. I tried searching for topics and when through 3 to 4 pages before making the post because I didn't see what I needed. Sorry if this is a duplicate post.
Thanks in advance