Go to next empty cell on another sheet

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I want to write code that will go to an empty cell on another sheet within the range Order!E2:N2. It would be good if the code took me to E2 if it is empty. If not, It would move to F2 etc. etc until It got to N2.


Thank You,
Michael
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Try this:

Code:
Sub test()
Dim i As Integer

With Sheets("Order")
    If Application.CountA(Range("E2:N2")) < 10 Then
        For i = 5 To 14
            If .Cells(2, i) = "" Then
                Application.Goto .Cells(2, i)
                Exit For
            End If
        Next i
    Else
        MsgBox "No cells available"
    End If
End With

End Sub
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Thank You.
It works great for my purposes. I filled every cell to see if it would give me a message box, It did not. I actually did nothing at all. It really is not a big deal, because I have never had each cell filled in.

Thank You again,
Michael
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686

ADVERTISEMENT

Ooops, that's probably because I just saw that I have a tiny error in the code. And I mean *tiny* :oops:

On this line:
Code:
If Application.CountA(Range("E2:N2")) < 10 Then

Add a period before the word Range. So you should have

Code:
If Application.CountA(.Range("E2:N2")) < 10 Then

Believe it or not, that makes a difference. Without the period, it was checking the cells on whatever the active sheet was--not the "Order" sheet. Now if you fill in all of the cells, you should get the message.
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Thank You again. That actually worked great. Could I some how have go to Cell E2 if there are no empty cells?
I like the idea of a message, then take me to E2 on the other page so I remove what is in this cell or make a change.

Thank You,
Michael
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Here is what I added and it seems to work fine.

With Sheets("What to Order")
If Application.CountA(.Range("E2:N2")) < 10 Then
For i = 5 To 14
If .Cells(2, i) = "" Then
Application.Goto .Cells(2, i)
Exit For
End If
Next i
Else
MsgBox "Need to make some room on the What to Order sheet to list the new job."
Application.Goto .Range("e2")
End If
End With
End Sub


Michael
 

Watch MrExcel Video

Forum statistics

Threads
1,119,264
Messages
5,577,076
Members
412,763
Latest member
sienweiw
Top