VBA to remove highlighted cells

Yamasaki450

Board Regular
Joined
Oct 22, 2021
Messages
62
Office Version
  1. 2021
Platform
  1. Windows
Hello again. :)

I would kindly ask for another VBA to remove red highlighted cells. Cells are highlighted with conditional formatting.

Thanks guys.
 

Attachments

  • 3.png
    3.png
    40.4 KB · Views: 11

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
@Yamasaki450
1. Please, remove the conditional formatting first
2. Run this code (you need to adjust the range):
VBA Code:
Sub Yamasaki450_10()
'=AND($C2=3,D2<=-4,D2>=-65)"
Dim c As Range
Dim i As Long, j As Long
Dim t As Double
t = Timer
'change the range to suit
Set c = Range("D2:E12")
va = c
vb = Range("C2:C12")

For i = 1 To UBound(vb, 1)
    If vb(i, 1) = 3 Then
        For j = 1 To UBound(va, 2)
            If va(i, j) <= -4 Then
                If va(i, j) >= -65 Then
                    va(i, j) = ""
                End If
            End If
        Next
    End If
Next

c = va
Debug.Print "Completion time:  " & Format(Timer - t, "0.00") & " seconds"
End Sub
Example:
Before:
Book2
CDE
1
21653
33-5-64
464-100-64
5212
63-5-66
733-3
83-4100
93-5-65
101-100-5
1165165
12-5-510
13
Sheet1

After:
Book2
CDE
1
21653
33
464-100-64
5212
63-66
733-3
83100
93
101-100-5
1165165
12-5-510
13
Sheet1
 
Upvote 1
Solution
Hi Yamasaki,
What have you tried so far?
See if you can create a macro that:
Sets a range, Ideally either a selection, or a hard coded range.
Then for each cell in the range check to see if the interior color is red.
if it is clearcontents.
if not move on.
 
Upvote 0
Hi Yamasaki,
What have you tried so far?
See if you can create a macro that:
Sets a range, Ideally either a selection, or a hard coded range.
Then for each cell in the range check to see if the interior color is red.
if it is clearcontents.
if not move on.
Hey. Thanks but i have no clue how to write macro code heh :) Thats why im asking here if someone is willing to write it.
 
Upvote 0
Does this macro do what you want (it physically clears the cells that are shown in red)...
VBA Code:
Sub ClearRedCells()
  Dim Cell As Range
  Application.ScreenUpdating = False
  For Each Cell In Range("F3:L23")
    If Cell.DisplayFormat.Interior.Color = vbRed Then
      Cell.Clear
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
If this is a follow-up question for the thread titled "vba-macro-to-delete-highlighted-cells," please provide the link to the thread so that everyone who reads this can understand the context. An important detail from the previous thread is that you are working with over 14 million cells.


Cells are highlighted with conditional formatting.
What is formula of the conditional formatting?
 
Upvote 0
If this is a follow-up question for the thread titled "vba-macro-to-delete-highlighted-cells," please provide the link to the thread so that everyone who reads this can understand the context. An important detail from the previous thread is that you are working with over 14 million cells.



What is formula of the conditional formatting?
I used this formulas to give cells color "=AND($C2=3,D2<=-4,D2>=-65)"

Post #2 in this thread.
 
Upvote 0
But in your example in post #1 there are no data in col C, why?
I didnt use formula in post #1. I did it manually with conditional formatting rule just to show what i want... I didnt know that formula is important... Here is example with formula.
 

Attachments

  • 4.png
    4.png
    50 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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