Message box for blank cell

ashani

Active Member
Joined
Mar 14, 2020
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Hi
I'm using the below code in VBA in my other sheets and it works perfectly fine. However, I want to use it for my new sheet but it doesn't work. The cells are merged F25:G26 is blank than system shouldn't allow the user to input anything F31:G32. The cells are merged. Please can someone guide me how should I do that.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target, Columns("A:B")) Is Nothing Then Exit Sub
    Dim cel As Range: Set cel = Target.Offset(, -2)
    If Not Intersect(Target, Range("F31:G32")) Is Nothing Then
        If cel = "" Then
            cel.Select
            MsgBox "Input data first above"
        End If
    End If

Application.CutCopyMode = False

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I am not sure why you are using a Worksheet_SelectionChange event instead of a Worksheet_Change event.

Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if update not in cells F31:G32
    If Intersect(Target, Range("F31:G32")) Is Nothing Then Exit Sub
    
'   Exit if nothing added to cell
    If Target = "" Then
        Exit Sub
    Else
'       Check cells F25:G26 for an entry
        If Range("F25") = "" Then
            MsgBox "Input data above first"
            Application.EnableEvents = False
            Range("F31:G32").ClearContents
            Application.EnableEvents = True
        End If
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,188
Members
448,554
Latest member
Gleisner2

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