Link to home
Start Free TrialLog in
Avatar of Kelly Kavanagh
Kelly Kavanagh

asked on

When entering data certain cells cannot be left blank.

I have a spreadsheet that has certain cells that cannot be left blank by the user entering the data.
(I have read similar questions/responses but they are not quite like mine as they are "before save/close" of the spreadsheet".... I need it done before they can go to the next cell)

There are 8 cells throughout the spreadsheet (highlighted in yellow) that need to be entered before the user clicks the "form control button" that is called "ADD RECORD" (this is a macro that takes all the information that was entered in Column B, including the hidden rows and pastes as values into another spreadsheet)

Any help would as always be great! :)  BIG thanks
Kelly

(spread sheet attached)
Book1.xlsx
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Hi,

Please try below code, replace the reference for moving to Sheet2 with your macro of adding records:
Sub AddRecords()
Dim Ws As Worksheet
Dim NeededCell(1 To 8) As String
Dim x
Set Ws = Worksheets("Sheet1") 'Change the sheet name as required
NeededCell(1) = Ws.Range("B6").Value
NeededCell(2) = Ws.Range("B7").Value
NeededCell(3) = Ws.Range("B21").Value
NeededCell(4) = Ws.Range("B22").Value
NeededCell(5) = Ws.Range("B36").Value
NeededCell(6) = Ws.Range("B37").Value
NeededCell(7) = Ws.Range("B51").Value
NeededCell(8) = Ws.Range("B52").Value
For x = 1 To 8
    If Len(NeededCell(x)) & vbNullString > 0 Then
        Sheets(2).Activate
        Sheets(2).Range("A1").Select 'Replace this range and Paste your macro here
    Else
        MsgBox "Your Form Is Incomplete, Please Complete The Form To Proceed"
        Ws.Range("B6").Select
        Exit Sub
    End If
Next x
End Sub

Open in new window

Please find attached for your reference.
Hope this helps.
AddRecords.xlsm
I have added sheet event code to remind the user when they enter a yellow cell. The Add Record button does a final check.

Option Explicit
''/// code for button
Sub AddRecord()
    Dim rCl As Range

    For Each rCl In ActiveSheet.Range("B6:B7,B21:B22,B36:B37,B51:B52")
        If IsEmpty(rCl) Then
            MsgBox "Please complete all yellow cells", vbCritical, "Input required"
            Application.EnableEvents = False
            rCl.Select
             Application.EnableEvents = True
            Exit Sub
        End If
    Next rCl
    ''///your code continues here
End Sub

Open in new window


''/// code in sheet event

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target

        If .Column = 2 And .Interior.ColorIndex = 6 And IsEmpty(Target) Then
            MsgBox "This cell must be completed", vbCritical, "Input required"
        End If

    End With
End Sub

Open in new window

CheckComplete.xlsm
Avatar of Kelly Kavanagh
Kelly Kavanagh

ASKER

I am not very good with looking at script and knowing where it goes....
The attached is what the "Add Record" button does....
I have no idea where I am supposed to put the script that you replied with? HELP!
thanks so much
Kelly
add-record.txt
Why not add the workbook and I'll amend it for you, most of the attached code is unnecessary and will slow down yoor code.

See attached
CheckComplete.xlsm
Hi Roy,

Sounds like a great idea to me!  (As I still do not understand...uggg!)

Thanks again:)
Kelly
Kelly,

Please find attached, if it works for you
Dorst-Data-Collection_KK_r---DO-NOT.xlsm
It doesn't work the same as the example that Roy sent back a few messages ago.... where he asked me to just send him my workbook.
(If you skip the cell it has a pop up right away....) I want that one in my workbook...
thanks,
Kelly
ASKER CERTIFIED SOLUTION
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome!!!! Thank you sooooo much! :):):)
Pleased to help