2 Variable function

vince012

New Member
Joined
Oct 24, 2022
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
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
--------------------------------------------------------------------------------------------
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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.

VBA Code:
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
 
Upvote 0
Solution
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
 
Upvote 0
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

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.

VBA Code:
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
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top