VBA Code to Desplay text format of cell when cell is empty

James Allensworth

New Member
Joined
Mar 26, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
In my worksheet cell A30, which is the anchor cell of multiple merged cells. I have the custom format "Comments/Clarifications:" @. When characters including spaces are entered in the merged range then the format appears. When the cell is empty of all characters including spaces then the merged range appears empty without the "Comments/Clarifications:" text. Which, as you know, is the way Excel operates. What I cant to do is use VBS Code to look at the cell when data has been deleted and insert a blank space so the formatted text statement will appear.

This what I have tried;

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
Set c = Range("a30")

If Selection.Count = 1 Then
If Not Intersect(Target, c) Is Nothing Then
c.Value = " " & c.Value On this command line I have also tried using a call statement to load a Macro which basically would put a space in cell a30
End If
End If
End Sub

Thank you for any thoughts or workarounds.
Jim
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I think your overall approach is bending over backwards to do something that would be easier to do a completely different way.

First, the use of merged cells is inadvisable, especially when using VBA. However, you would still have this same question without the merged cells.

I would redesign your sheet to use a cell to have the label "Comments/Clarifications" instead of using a custom format to put it in the same cell with the data. That just eliminates the whole problem.
 
Upvote 0
Thank you for your thoughts. Maybe that is what I will need to do in the end. Still hoping that someone will have the answer.
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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