Combine of placeholder and select cells scripts in VBA

VBAEXCELNew

New Member
Joined
Apr 3, 2023
Messages
38
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

i have a script where i want my Cell C14 to be a placeholder script, where if cell b14 were to be selected as "Others" in a drop down list

Example:

1681002187655.png



Currently i have found that there is a place holder where it nicely if were put in C 14 However due to a condition in B14 i dont wan my placeholder to be show
in every cell i selected in B14
my script currently i am using is this
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Target is passed as an argument when the event fires. It is the Range that changed and caused the event to fire.
' You can use it to run your code only when certain cells change.

If Target.CountLarge > 1 Then Exit Sub
'Returns a value that represents the number of objects in the collection.
'The CountLarge property is functionally the same as the Count property, except that the Count property will
'generate an overflow error if the specified range has more than 2,147,483,647 cells (one less than 2,048 columns).


If Target.Address <> "$B$14" Then Exit Sub
'Target the address not = cell b14


    If Target = "Others" Then
       With Target.Offset(0, 1)
            .Value = "Please Specify"
            '.Font.Italic = True
            .Font.Color = Black
            '.Font.ColorIndex = 16
            .Borders.LineStyle = xlContinuous
       End With
    Else
        With Target.Offset(0, 1)
            .ClearContents
            '.Font.Italic = False
            .Borders.LineStyle = xlNone
       End With
    End If
End Sub

Currently i have found this VBA script for Placeholder
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const PlaceHolder As String = "Please Specify" 'Change what you want the place holder to be
Dim DesiredPlaceHolderCells As Range, C As Range


Set DesiredPlaceHolderCells = Range("$C$14") 'Change cell(s) that you want to act as place holders within the "" marks, seperated by commas


If Target.CountLarge > 1 Then GoTo Skip


If Not Intersect(DesiredPlaceHolderCells, Target) Is Nothing And Target.Value = PlaceHolder Then
        Target.Font.Color = vbBlack
        Target = ""
End If


Skip:
For Each C In DesiredPlaceHolderCells
    If C = "" And C.Address <> Target.Address Then
        C.Font.ColorIndex = 16 'grey
        C = PlaceHolder
    End If
Next C


End Sub

Now how can i combine my placeholder script to the above i am using for ?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

Do you want to Combine a Private Sub Worksheet_Change(ByVal Target As Range) Event
with
a Private Sub Worksheet_SelectionChange(ByVal Target As Range) Event ???
Please explain
 
Upvote 0
Hi,

Do you want to Combine a Private Sub Worksheet_Change(ByVal Target As Range) Event
with
a Private Sub Worksheet_SelectionChange(ByVal Target As Range) Event ???
Please explain
Correct i would like to combine them if possible if not maybe i would like my placeholder vba to work like on select the cell do the method
 
Upvote 0
Sorry I meant can you clarify what you would precisely to happen ...

What is your range of cells which needs to trigger the Event Macro ... if it is not just cell B14 ?
 
Upvote 0
Sorry I meant can you clarify what you would precisely to happen ...

What is your range of cells which needs to trigger the Event Macro ... if it is not just cell B14 ?
it is used to write the place holder at C14
where if b14 is select at other this placeholder will appear "Please specify"
else this placeholder is removed
 
Upvote 0
OK ...

But what is the difference between this request .... and your previous request :
 
Upvote 0
OK ...

But what is the difference between this request .... and your previous request :
currently i like my vba script to work with the placeholder i have
where the placeholder vba script is place in the cell without condition
 
Upvote 0
Sorry ... but I have a lot of difficulty understanding ...

Hope another contributor will understand your request ...
 
Upvote 0
Sorry ... but I have a lot of difficulty understanding ...

Hope another contributor will understand your request ...
Sry let me phase
as currently the code u previous give me dont feel like a place holder as it is just a value
is there any way i can change ur code to make it like a place holder
where the place holder font is grey etc and when user not type anything in the cell the value reappear again

and when user type in the font color will be back to black

hope u have an better understand of what i trying to mean
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
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