VBA Clear Contents

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm working with a Column H, where sometimes it provides an Interior.Color = IIf(b, RGB(255, 0, 0) with a specific value of "Enter Texts".

Is there a code that I can run that when this happens for example at cell H11 and when cell I11 is blank that I can run to allow me to clear the contents of H11?

Also, when this happens at cell H12 and when cell I12 is blank that I can run to clear the contents of H12?

And so on...

Please let me know!

Thank you!
Pinaceous
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Assum column H starts from H11 and down
It loops column I to find blank cell, then delete column H content
VBA Code:
Sub test()
Dim cell As Range
For Each cell In Range("I11:I" & Cells(Rows.Count, "H").End(xlUp).Row)
    If IsEmpty(cell) Then cell.Offset(0, -1).ClearContents
Next
End Sub
 
Upvote 0
Assum column H starts from H11 and down
It loops column I to find blank cell, then delete column H content
VBA Code:
Sub test()
Dim cell As Range
For Each cell In Range("I11:I" & Cells(Rows.Count, "H").End(xlUp).Row)
    If IsEmpty(cell) Then cell.Offset(0, -1).ClearContents
Next
End Sub
Thanks bebo021999!

My column count is long and the code does take time to run.

Do you know if more variables can be added to speed this process up?

Many thanks!
pinaceous
 
Upvote 0
Try again:
VBA Code:
Sub clear()
Range("I11:I" & Cells(Rows.Count, "H").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Offset(0, -1).ClearContents
End Sub
 
Upvote 0
Another option
VBA Code:
Sub Pinaceous()
   With Range("H2", Range("H" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if((@=""Enter Texts"")*(" & .Offset(, 1).Address & "=""""),"""",@)", "@", .Address))
   End With
End Sub
 
Upvote 0
Hey Fluff,

Your code works well.

But, can you please adjust your code to ignore any entry that is not an interior color Red with "Enter Texts" for example a number entry and to please ignore any blank cells?

Because right now, it is providing a "0" for any blank cells, which I do not want it to do.

Thank you!
Respectfully,
pinaceous
 
Upvote 0
It already ignores any cell that does not have "Enter Texts", so not sure what you mean.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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