VBA to remove highlighted cells

Yamasaki450

Board Regular
Joined
Oct 22, 2021
Messages
71
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: 24

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
@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
@Yamasaki450
1. Please, remove the conditional formatting first
2. Run this code (you need to adjust the range):
Nice. :) This works very fast now... I didnt realize this can be done without conditional formatting. Big thanks Akuini for your time and effort... And also thanks to all others for helping me out.
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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