tropics123
Board Regular
- Joined
- May 11, 2016
- Messages
- 85
Hi! Could someone help me tweak this macro? I want the macro to find specific texts in the header and (the text will appear multiple times) and delete everything in that column but don't delete the header. For example, I want the macro to look for "Mary Lee" and "Bob Smith" in the header and delete everything in the column below Mary Lee and Bob Smith's name but leave Mary Lee and Bob Smith's name in the header.
This is the before table:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Luke Skywalker[/TD]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Mary Lee[/TD]
[TD]Joe Watson[/TD]
[/TR]
[TR]
[TD]$450[/TD]
[TD]$2000[/TD]
[TD]$90[/TD]
[TD]$78[/TD]
[TD]$88[/TD]
[TD]$67[/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]$57[/TD]
[TD]$709[/TD]
[TD]$19[/TD]
[TD]$59[/TD]
[TD]$39[/TD]
[TD]$78[/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]$98[/TD]
[TD]$39[/TD]
[TD]$35[/TD]
[TD]$56[/TD]
[TD]$28[/TD]
[TD]$55[/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
After:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Luke Skywalker[/TD]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Mary Lee[/TD]
[TD]Joe Watson[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$90[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$35[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$6560
[/TD]
[/TR]
</tbody>[/TABLE]
Here's my macro but it's deleting everything in the column including the header. Thank you for your help!
Sub Delete()
' Delete cells below header with specific text but don't delete header
Sheets("Sheet3").Select
Dim A As Range
Do
Set A = Rows(1).Find(What:="Mary Lee", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(What:="Bob Smith", LookIn:=xlValues, lookat:=xlPart)
If A Is Nothing Then Exit Do
A.EntireColumn.Delete
Loop
End Sub
This is the before table:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Luke Skywalker[/TD]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Mary Lee[/TD]
[TD]Joe Watson[/TD]
[/TR]
[TR]
[TD]$450[/TD]
[TD]$2000[/TD]
[TD]$90[/TD]
[TD]$78[/TD]
[TD]$88[/TD]
[TD]$67[/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]$57[/TD]
[TD]$709[/TD]
[TD]$19[/TD]
[TD]$59[/TD]
[TD]$39[/TD]
[TD]$78[/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]$98[/TD]
[TD]$39[/TD]
[TD]$35[/TD]
[TD]$56[/TD]
[TD]$28[/TD]
[TD]$55[/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
After:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Luke Skywalker[/TD]
[TD]Mary Lee[/TD]
[TD]Bob Smith[/TD]
[TD]Mary Lee[/TD]
[TD]Joe Watson[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$90[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]$35[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$6560
[/TD]
[/TR]
</tbody>[/TABLE]
Here's my macro but it's deleting everything in the column including the header. Thank you for your help!
Sub Delete()
' Delete cells below header with specific text but don't delete header
Sheets("Sheet3").Select
Dim A As Range
Do
Set A = Rows(1).Find(What:="Mary Lee", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(What:="Bob Smith", LookIn:=xlValues, lookat:=xlPart)
If A Is Nothing Then Exit Do
A.EntireColumn.Delete
Loop
End Sub