Finding next available row and making data entry required

Aprez76

New Member
Joined
Aug 7, 2008
Messages
23
Hi all,

I'm attempting to write a macro that will "loop until", down a given column (column a) until it finds a blank cell. Once the cell is identified I would like the focus to be on that cell and remain there until an entry/input is made by a user. Perhaps even a message box when a user tries to leave the cell without entering any information to say this field is required before moving on.

Any assistance is most appreciated.

Andrew
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You should be able to work with the following two functions. The first one sets the focus on the first empty cell in the column of interest. It requires that the focus was on a non-empty cell further up in the column:

Code:
Option Explicit
Public r As Range
Sub SetFocusOnNextEmptyCell()
    Set r = Selection.End(xlDown).Offset(1)
    r.Select
End Sub

If you now also include the following event handler in the VBA section for the worksheet of interest you should find that your user can't leave the first empty cell before he/she entered some text or number:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not r Is Nothing Then
        If r.Value = "" Then
            Set Target = r
            r.Select
        End If
    End If
End Sub

Hope this helped,
Rolf
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

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