Not sure I understand what you're trying to do. but Excel can be pretty smart sometimes:
Option Explicit
Public Function Add_Blanks(Optional var1 As Variant = 0#, Optional var2 As Variant = 0#) As Double
If IsNumeric(var1) And IsNumeric(var2) Then
Add_Blanks = CDbl(var1) + CDbl(var2)
ElseIf IsNumeric(var1) And Not IsNumeric(var2) Then
Add_Blanks = CDbl(var1)
ElseIf Not IsNumeric(var1) And IsNumeric(var2) Then
Add_Blanks = CDbl(var2)
Else
Add_Blanks = 0#
End If
End Function
Private Sub tadd()
Dim D As Double
Dim L As Long
MsgBox ("Answer is ... " & Add_Blanks(10, 20))
MsgBox ("Answer is ... " & Add_Blanks(, 20))
MsgBox ("Answer is ... " & Add_Blanks(10))
MsgBox ("Answer is ... " & Add_Blanks)
MsgBox ("Answer is ... " & Add_Blanks(10, vbNull))
MsgBox ("Answer is ... " & Add_Blanks("-10.222", "-20.111"))
ActiveSheet.Cells(1, 1).Value = 1234
ActiveSheet.Cells(1, 2).Value = 5678
ActiveSheet.Cells(1, 3).Value = "CAT and DOG"
MsgBox ("Answer is ... " & Add_Blanks(ActiveSheet.Cells(1, 1).Value, ActiveSheet.Cells(1, 2).Value))
MsgBox ("Answer is ... " & Add_Blanks(ActiveSheet.Cells(1, 1).Value, ActiveSheet.Cells(1, 2).Value))
MsgBox ("Answer is ... " & Add_Blanks(ActiveSheet.Cells(1, 1).Value, ActiveSheet.Cells(1, 3).Value))
End Sub
I'm guessing from the way I read your code that you want to add numbers, even if one or both is 'blank'
What is it you're trying to do in words (not VBA) please
Paul