Empty Rows & colomns

K

Khalil Handal

Hi evryone

need a VB code to find first empty row
and
first empty colomn.

apretiate any help
Khalil
 
E

Ed Ferrero

Hi Khalil,

Function FirstEmpty(what As String) As Long
Dim r As Range
If what = "row" Then
For Each r In ActiveSheet.Rows
If WorksheetFunction.CountA(r) = 0 Then
FirstEmpty = r.Row
Exit Function
End If
Next
ElseIf what = "col" Then
For Each r In ActiveSheet.Columns
If WorksheetFunction.CountA(r) = 0 Then
FirstEmpty = r.Column
Exit Function
End If
Next
End If
' no empty rows (or columns), return zero
FirstEmpty = 0
End Function

Sub test()
Debug.Print FirstEmpty("row")
Debug.Print FirstEmpty("col")
End Sub

Ed Ferrero
http://www.edferrero.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top