Hi Hally, try this code instead:
Public Sub myMacro()
Dim oper As String
Dim oValue As Long
Dim oCell As String
Dim sht1 As Worksheet, sht2 As Worksheet
With Sheets("work")
Set sht1 = Sheets(.Range("F6").Text)
Set sht2 = Sheets(.Range("G6").Text)
oCell = .Range("E6").Text
oper = .Range("C6").Text
oValue = .Range("D6").Value
End With
Select Case oper
Case Is = "+"
sht2.Range(oCell).Value = sht1.Range(oCell).Value + oValue
Case Is = "*"
sht2.Range(oCell).Value = sht1.Range(oCell).Value * oValue
Case Is = "/"
sht2.Range(oCell).Value = sht1.Range(oCell).Value / oValue
Case Is = "-"
sht2.Range(oCell).Value = sht1.Range(oCell).Value - oValue
Case Else
MsgBox "Operator must be +, -, * or /"
End Select
End Sub
After pasting this code into your module, remember to right-click on your command button, select 'Assign Macro' and choose 'myMacro' from the list of available macros. Set your values in cells C6:G6 on sheet 'work' and click the button. The sheet listed in G6 will be updated accordingly.
Bookmarks