Need Help creating a VBA for 3 empty fields

dcme27

New Member
Joined
Dec 9, 2019
Messages
4
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello. I have basically no experience creating macros in Excel, but I am looking to make one for cells A2, A3, A4 to show text in the field if the field is empty.

I found one online, but after I paste it in and try and run, it pops up a "Macro" box, but no Macros to select. Below is the data I found online:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$4" Then
        If Target = "" Then
            ' Cell is empty; mark it and make gray
            Target = "(Customer Name)"
            With Selection.Font
                .ThemeColor = xlThemeColorDark1
                .TintAndShade = -0.249977111117893
            End With
        Else
            ' Cell contains something; remove gray
            With Selection.Font
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
            End With
        End If
    End If
End Sub
A2-4.JPG
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
.
Is this what you were seeking :

VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = "$B$4" Then
        If Target.Value = "" Then
            ' Cell is empty; mark it and make gray
            Target.Value = "(Customer Name)"
            With Selection.Font
                .ThemeColor = xlThemeColorDark1
                .TintAndShade = -0.249977111117893
            End With
        Else
            ' Cell contains something; remove gray
            With Selection.Font
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
            End With
        End If
    End If
End Sub
 
Upvote 0
Hi,
try following & see if does what you want

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("B2:B4")) Is Nothing Then
    EntryComplete Target
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("B2:B4")) Is Nothing Then
    EntryComplete Target
    End If
End Sub

Sub EntryComplete(ByVal Target As Range)
    Dim CellText As String
    On Error GoTo exitsub
    
    CellText = Choose(Target.Row - 1, "(Customer Name)", _
                                      "(Employee Number)", _
                                      "(Employee Title)")
    
    Application.EnableEvents = False
        If Target = "" Then
' Cell is empty; mark it and make gray
            Target = CellText
            With Target.Font
                .ThemeColor = xlThemeColorDark1
                .TintAndShade = -0.249977111117893
            End With
        Else
            If Not Target = CellText Then
' Cell contains something; remove gray
            With Target.Font
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
            End With
            End If
        End If
exitsub:
    Application.EnableEvents = True
End Sub


Dave
 
Upvote 0
Thank you... Your code looks great, but I have no idea why I can't get it to actually do anything. Definitely user error on this. I appreciate your help.
 
Upvote 0
Thank you... Your code looks great, but I have no idea why I can't get it to actually do anything. Definitely user error on this. I appreciate your help.

where have you placed the codes? They should be in your worksheets code page.

Dave
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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