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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,406
Members
448,958
Latest member
Hat4Life

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