VBA Modification

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
341
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I need help with this code that I have put together:

Private Sub worksheet_selectionchange(ByVal target As Range)
Static LastCell As Range

If Not LastCell Is Nothing Then
If LastCell.Column = 16 Then
If Not IsEmpty(LastCell.Offset(0, -1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank.")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If

Set LastCell = ActiveCell

If Not LastCell Is Nothing Then
If LastCell.Column = 15 Then
If Not IsEmpty(LastCell.Offset(0, 1)) Then
If IsEmpty(LastCell) Then
MsgBox (" Cell cannot be blank")
Application.EnableEvents = False
LastCell.Select
Application.EnableEvents = True
End If
End If
End If
End If

Set LastCell = ActiveCell

End Sub

What I am trying to achieve is a pop-up if a cell in column O is blank but the cell in column P is not blank and vice versa.

It works when cell in column O is not blank and you try to leave cell in column P blank but it let's you leave cell in column O blank and populate cell in column P and go to the next row unless you go back to the cell in column O afterwards!

Or if you know of a better way to code this, please let me know.

Thanks.
 
Thanks a lot.

As soon as I enter a number in column D (regardless of what it starts with) it fails as shown below:

1582898058471.png
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Adjusted and tested, this works for me if the first character entered in column D is "4":
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim s   As String

    With Target
        If .CountLarge > 1 Or .Value = "" Then Exit Sub
        If .Column = 4 And Left$(.Value, 1) = .Column Then s = "Don't forget to fill column H"
        If .Column = 8 And Len(.Value & .Offset(, 1).Value) = Len(.Value) Then s = "Missing column name"
        If .Column = 9 And Len(.Value & .Offset(, -1).Value) = Len(.Value) Then s = "Missing column number"
    End With
  
    If s <> "" Then MsgBox s, vbInformation, "Enter missing details"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,903
Members
449,132
Latest member
Rosie14

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