In my excel table, I want to write a code for conditional formating that will highlight…
- User
In my excel table, I want to write a code for conditional formating that will highlight all cells that are blank. How can I do this
- Assistant
- Select the range of cells that you want to apply the conditional formatting to.
- Click on the "Home" tab in the Excel ribbon.
- Click on the "Conditional Formatting" button.
- Click on "New Rule" in the drop-down menu.
- In the "New Formatting Rule" dialog box, select "Use a formula to determine which cells to format".
- In the "Format values where this formula is true" field, enter the following formula: =ISBLANK(A1) (replace A1 with the first cell in your selected range).
- Click on the "Format" button to select the formatting that you want to use for the highlighted cells.
- Click "OK" to close the "Format Cells" dialog box.
- Click "OK" again to close the "New Formatting Rule" dialog box.
- The conditional formatting will now be applied to the selected range and any blank cells will be highlighted according to the formatting that you chose.
- User
In Excel VBA can I write a code for a column range where if I double click the first time on a cell the value Yes is added to it, if I double click the seconf time the value No is added and if I double click the third time the cell returns back to blank
- Assistant
Yes, you can write a code in Excel VBA for this.
- First, select the column range where you want the double-click functionality to work.
- Press "Alt + F11" on your keyboard to open the VBA Editor.
- In the VBA Editor, double-click on the worksheet where you want to apply the code.
- Paste the following code in the worksheet module:
codePrivate Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim count As Integer count = 1 If Intersect(Target, Range("A1:A10")) Is Nothing Then Exit Sub 'change the range to match your selected column range Application.EnableEvents = False On Error Resume Next count = Target.Value + 1 If count = 4 Then count = "" Target.Value = IIf(count = 1, "Yes", IIf(count = 2, "No", count)) Cancel = True Application.EnableEvents = True End Sub- Modify the range ("A1:A10") in the code with the range you selected in Step 1.
- User
I ran the code and on the first double click it change the cell value form blank to Yes. On the next double click, nothing happened
- Assistant
Sorry about that, the code should be modified as follows to make it work:
codePrivate Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim count As Long count = 0 If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'change the range to match your selected column range Application.EnableEvents = False If IsEmpty(Target) Then Target.Value = "Yes" Else If Target.Value = "Yes" Then Target.Value = "No" ElseIf Target.Value = "No" Then Target.Value = "" End If End If Cancel = True Application.EnableEvents = True End If End SubWhat this code does is keep track of the number of times a cell has been double-clicked, and changes the cell value accordingly.
Please try the modified code and let me know if it works for you.