-1

As shown, test1 calls FillEmptyWith but it gives me a

Compile Error: = Expected

Could someone help?

Sub FillEmptyWith(Range, val)
    For Each cell In Range
        If IsEmpty(cell) Then
            cell.Value = val
        End If
    Next cell
End Sub

Sub test1()
   FillEmptyWith ((Sheets("In Force Earnix").Range("S10:S20")),"N")
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Garry W
  • 303
  • 2
  • 10
  • 2
    I would avoid using `Range` or `val` as variable names. And don't wrap the first argument in parentheses when you call your sub. – Tim Williams Jun 27 '19 at 20:26

2 Answers2

5

I would avoid using Range or val as variable names.

And don't wrap the first argument in parentheses when you call your sub (since it will cause that range to be passed to your sub as a 2-D array instead of a Range object).

You don't need parentheses at all when calling a sub.

Sub FillEmptyWith(rng As Range, v)
    Dim cell as range
        For Each cell In rng.Cells
        If IsEmpty(cell) Then
            cell.Value = val
        End If
    Next cell
End Sub

Sub test1()
    FillEmptyWith Sheets("In Force Earnix").Range("S10:S20"),"N"
End Sub

Related: VBA: Usage of parentheses for a method

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
0

As @TimWilliams noted, parenthesis causes a problem. If you prefer, you can use parenthesis, but only one pair:

Call FillEmptyWith(Sheets("In Force Earnix").Range("S10:S20"),"N")
JohnyL
  • 6,894
  • 3
  • 22
  • 41