Hello,
I'm teaching myself VBA and ran into an problem I cannot solve.
I'd like to click the button I made so that it automatically knows what column to refer to when performing the macro.
The macro currently works if I select the cell then press the button. But I would like the button to automatically know which column of cells to perform the function on.
Here is my code:
Sub Sheet3Grades()
Dim score As Integer
score = ActiveCell.Value
If score >= 100 And score <= 199 Then
ActiveCell(1, 2).Value = "F"
ActiveCell(1, 2).Interior.Color = RGB(255, 0, 0)
ElseIf score >= 200 And score <= 299 Then
ActiveCell(1, 2).Value = "D"
ActiveCell(1, 2).Interior.Color = RGB(255, 178, 229)
ElseIf score >= 300 And score <= 499 Then
ActiveCell(1, 2).Value = "C"
ActiveCell(1, 2).Interior.Color = RGB(204, 204, 255)
ElseIf score >= 500 And score <= 599 Then
ActiveCell(1, 2).Value = "B"
ActiveCell(1, 2).Interior.Color = RGB(153, 255, 255)
ElseIf score >= 600 And score <= 699 Then
ActiveCell(1, 2).Value = "A"
ActiveCell(1, 2).Interior.Color = RGB(0, 255, 0)
ElseIf score >= 700 And score <= 799 Then
ActiveCell(1, 2).Value = "A+"
ActiveCell(1, 2).Interior.Color = RGB(255, 255, 0)
End If
End Sub
I'm teaching myself VBA and ran into an problem I cannot solve.
I'd like to click the button I made so that it automatically knows what column to refer to when performing the macro.
The macro currently works if I select the cell then press the button. But I would like the button to automatically know which column of cells to perform the function on.
Here is my code:
Sub Sheet3Grades()
Dim score As Integer
score = ActiveCell.Value
If score >= 100 And score <= 199 Then
ActiveCell(1, 2).Value = "F"
ActiveCell(1, 2).Interior.Color = RGB(255, 0, 0)
ElseIf score >= 200 And score <= 299 Then
ActiveCell(1, 2).Value = "D"
ActiveCell(1, 2).Interior.Color = RGB(255, 178, 229)
ElseIf score >= 300 And score <= 499 Then
ActiveCell(1, 2).Value = "C"
ActiveCell(1, 2).Interior.Color = RGB(204, 204, 255)
ElseIf score >= 500 And score <= 599 Then
ActiveCell(1, 2).Value = "B"
ActiveCell(1, 2).Interior.Color = RGB(153, 255, 255)
ElseIf score >= 600 And score <= 699 Then
ActiveCell(1, 2).Value = "A"
ActiveCell(1, 2).Interior.Color = RGB(0, 255, 0)
ElseIf score >= 700 And score <= 799 Then
ActiveCell(1, 2).Value = "A+"
ActiveCell(1, 2).Interior.Color = RGB(255, 255, 0)
End If
End Sub