0

It turns as code 13 mismatch problem when gets to ggem line. Can you please tell me what I'm doing wrong.

Sub sample()

    ActiveSheet.Range("C87").Select
    
   
For lo = 0 To 20
    For i = 0 To 8
    gg = ActiveCell.Offset(-2, i)
    ga = ActiveCell.Offset(-1, i)
    ggem = gg * 0.5 + ga * 0.5
    ActiveCell.Offset(-2, i).Value = ggem
    Next i
Next lo
    If Cells(91, 2).Value < 0.5 Then
    MsgBox ("text'")
    Else
    MsgBox ("text.")
    End If

End Sub 
  • Most likely `gg` or `ga` isn't numeric. – BigBen Feb 12 '21 at 17:19
  • what is the value of `gg` and `ga`? did u declarate this variable `as integer/double` (other numeric) type? u can add condition to do math `if isnumeric(gg) = true ` – Tomasz Feb 12 '21 at 17:19
  • 1
    Start by adding `Option Explicit` to the top of every code module (VB editor setting is "Require variable declaration", and will auto-add it for you going forward) and fixed everything that the editor then complains about. – Tim Williams Feb 12 '21 at 17:25
  • 1
    Then [avoid `Select` and `ActiveCell`](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – BigBen Feb 12 '21 at 17:28
  • Watch for worksheet errors (`#N/A`, `#REF!`, `#VALUE!`, `#NAME?`, etc.); the data type of such a cell would be `Variant/Error`, and doing math (or string concatenations, or even just a value comparison) against that data type will always throw a *type mismatch* error 13. Use the `IsError` VBA function to determine if a value has the `Error` variant subtype. – Mathieu Guindon Feb 12 '21 at 18:44

0 Answers0