VBA: Cbeck cell if empty, dependent on other cells

JennV

New Member
Joined
May 9, 2019
Messages
34
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Header1
[/TD]
[TD]Header2
[/TD]
[TD]Header3
[/TD]
[/TR]
[TR]
[TD]Cat
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Hello there,

I currently have this code:

Set CheckC = Range("B2")
If Range("A2") = Value And Range("B2") = "" Then
MsgBox "You cannot transfer until required information has been completed." & _
vbCrLf & vbNewLine & "Check for cells with light blue markings (All cells highlighted in light blue must be completed.)"
CheckC.Select
If Range("A2") = Value And IsEmpty(CheckC) Then Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
End If

My goal is, if the user has data in column A, then the corresponding B column must be filled out. So, if A2 is filled out, then B2 must also be filled out and this is applied to the entire set of data. Any help is much appreciated! I'm not VBA-savvy so if the code above is not making sense (well, obviously it's not because it's not working), please forgive me...
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi JennV - Welcome to the forum. Maybe this will help get things started. Please explain what happens when you run your code. That may help us help you. Hope this helps.
 
Upvote 0
Try this "Worksheet_Change" event :-
Paste entire code in Worksheet Module (Alt + F11")

Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]Set[/COLOR] Rng = IIf(Rng.Address(0, 0) = "A1:A2", Range("A2"), Rng)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] Dn <> "" And Dn.Offset(, 1) = "" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Not Target.Address = Dn.Address [COLOR="Navy"]Then[/COLOR]
        MsgBox "Please enter data in " & Dn.Offset(, 1).Address
        Application.EnableEvents = False
            Target = ""
        Application.EnableEvents = True
    [COLOR="Navy"]Exit[/COLOR] For
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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