I have only recently started picking up VBA in excel and I have been going through various tutorials online but I have encountered a bit of a problem when getting to if statements. Based on the knowledge i have gained online and from my VB knowledge i came up with the following code.
Private Sub CommandButton1_Click()
Dim mynum As Integer, checker As String
mynum = Range("A1:A10").value
If mynum > 0 Then
checker = "check"
Else
checker = "missing"
End If
Range("B1:B10").value = checker
End Sub
The idea is that if there is a number over 0 in column a, the adjacent cell in column b is checked, if however its 0 or lower the adjacent cell says missing (if that makes any sense) theres no real point to this as I am learning the basics at the moment 🙂
Now my problem…basically when i attempt to debug this, I get the Type Mismatch error and i cant really see why this is so. I know that it works when i set the range as one cell rather than multiple cells so my best guess is that it has something to do with that. I have looked into it but again im getting results that only back up that this should work. I must have misread it somewhere but help would be appreciated. 🙂
You cannot Assign/Check values of range like this for what you are trying to do. One way would be to loop through your range. For Example
EDIT
BTW, you don’t need VBA for this. If you are open for a Non VBA solution then simply put this formula in Cell B1 and copy it down