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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,622
Messages
5,832,739
Members
430,160
Latest member
a_majda

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
Top