# 2 Variable function



## vince012 (Dec 28, 2022)

Hi, guys! I want to create a two variable function that will check a column and iterate in its rows to find a blank cell, but I can't find a way to return the row and column value to my sub. Any help will do, Thanks!

*Sample code:*
--------------------------------------------------------------------------------------------
Public Sub Testing()
x = 2
y = 5
Blank_finder (x, y) 
End Sub
---------------------------------------------------------------------------------------------
Public Function Blank_finder(ByVal x As Integer, ByVal y As Integer) As Integer

Do While Cells(x, y).Value <> ""
    x = x + 1
Loop
 --------------------------------------------------------------------------------------------


----------



## bferraz (Dec 28, 2022)

Hey, adapted your code and now it will return on variable "Row" which was the first empty row. You can get the column in variable "y" as you provided it.


```
Public Sub Testing()
x = 2
y = 1
Row = Blank_finder(x, y)
End Sub

Public Function Blank_finder(ByVal x As Integer, ByVal y As Integer) As Integer

Do While Cells(x, y).Value <> ""
x = x + 1

    If Cells(x, y).Value = "" Then
    
        Blank_finder = x
        Exit Function
        
    End If
Loop

End Function
```


----------



## vince012 (Dec 28, 2022)

Thanks, man!

for reference we shorten the code in public function, like this:

Public Function Blank_finder(ByVal x As Integer, ByVal y As Integer) As Integer

Do While Cells(x, y).Value <> ""
x = x + 1

Loop

Blank_finder = x


----------



## bferraz (Dec 28, 2022)

vince012 said:


> Thanks, man!
> 
> for reference we shorten the code in public function, like this:
> 
> ...



Totally my bad, you are right, the best option is by only adding the Blank_finder row since there is the condition on Do While.


```
Public Function Blank_finder(ByVal x As Integer, ByVal y As Integer) As Integer

Do While Cells(x, y).Value <> ""
x = x + 1
Blank_finder = x
Loop

End Function
```


----------

