VBA - Remove text if a condition is met

cvrband

Board Regular
Joined
Jan 6, 2016
Messages
61
Office Version
  1. 365
Platform
  1. Windows
I have a file with only 1 worksheet that contains all text. I am looking for a VBA solution to loop through column 'D' in my example to look for groups of text that are not empty. Next, I need to determine if each group of text contains only 3/8" or if the group has text that would be a larger value if it were numerical (if it wasn't text), such as 1/2", 5/8", 3/4", 7/8", 1", etc. If the group contains any higher value than 3/8", everything in that particular group is kept, but if the group only contains 3/8", columns B, C, and D for that group would be deleted. The example data below hopefully illustrates what I'm trying to do. Thank you in advance.

Book1.xlsm
ABCDEFGH
1LineOriginalExpected Results for Cols B,C,D
21texttext3/8"
32
43texttext3/8"texttext3/8"
54texttext3/8"texttext3/8"
65texttext5/8"texttext5/8"
76texttext1/2"texttext1/2"
87texttext3/8"texttext3/8"
98
109texttext3/8"
1110texttext3/8"
1211
1312texttext7/8"texttext7/8"
1413
1514
1615texttext3/4"texttext3/4"
1716texttext3/8"texttext3/8"
1817texttext3/8"texttext3/8"
1918
Sheet1
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
VBA Code:
Sub cvrband()
   Dim Rng As Range
   
   For Each Rng In Range("D:D").SpecialCells(xlConstants).Areas
      If Application.CountIfs(Rng, "<>3/8""") = 0 Then
         Rng.Offset(, -2).Resize(, 3).ClearContents
      End If
   Next Rng
End Sub
 
Upvote 0
Solution
Thanks, Fluff! Manipulating the code you provided did the job. '.SpecialCells(xlConstants).Areas' is something that I haven't seen before. Clever!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,047
Members
449,064
Latest member
scottdog129

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