Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel/VBA: Passing a single cell as argument

Tags:

excel

vba

I want to make my custom VBA function accept only a single-cell argument. What is the rightway of doing it:

  • pass myCell as Cell

or:

  • pass myRange as Range and get (how?) the left-upper cell by default?
like image 214
user776686 Avatar asked Jan 23 '13 12:01

user776686


1 Answers

If you select more than one cell the function will exit:

Function AcceptOneCell(rng As Range)

If (rng.Cells.Count > 1) Then
    AcceptOneCell = "Only allow 1 cell"
    Exit Function
End If

    ' your code here

End Function
like image 187
InContext Avatar answered Sep 28 '22 02:09

InContext