deleting range macro

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
648
Office Version
  1. 365
  2. 2010
right now i look for "TSYHLD" and delete that row and all the rows it above until row 6

Rich (BB code):
Cells.Find(What:="hld", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Range("A6:AK1189").Select
    Selection.Delete Shift:=xlUp

so TSYHLD will not always be on row 1189...it possible to do a dynamic range so delete the TSYHLD row and all rows until row 6 no matter which row TSYHLD will be on?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
right now i look for "TSYHLD" and delete that row and all the rows it above until row 6

Rich (BB code):
Cells.Find(What:="hld", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Range("A6:AK1189").Select
    Selection.Delete Shift:=xlUp

so TSYHLD will not always be on row 1189...it possible to do a dynamic range so delete the TSYHLD row and all rows until row 6 no matter which row TSYHLD will be on?
What is TSYHLD and how is it related to the cell containing "hld"?

Is the row that finding "hld" on what you want to replace the 1189 with?
 
Upvote 0
What is TSYHLD and how is it related to the cell containing "hld"?

Is the row that finding "hld" on what you want to replace the 1189 with?

yes..sorry shouldve written "tsyhld" in the macro to be safer
...

also AFTER deleting the rows....i want to find "RULEID" then the macro to delete that ENTIRE ROW (no speicfic range required) and all the ones below it
 
Upvote 0
yes..sorry shouldve written "tsyhld" in the macro to be safer
...

also AFTER deleting the rows....i want to find "RULEID" then the macro to delete that ENTIRE ROW (no speicfic range required) and all the ones below it
Does this macro do what you want...
Code:
Sub DeleteAboveTSYHLDandBelowRULEID()
  On Error Resume Next
  Range("A6", Cells.Find("tsyhld", , xlFormulas, xlPart, , , False, False)).EntireRow.Delete
  Range(Cells.Find("ruleid", , xlFormulas, xlPart, , , False, False), Cells(Rows.Count, "A")).EntireRow.Delete
  On Error GoTo 0
End Sub
 
Upvote 0
Does this macro do what you want...
Code:
Sub DeleteAboveTSYHLDandBelowRULEID()
  On Error Resume Next
  Range("A6", Cells.Find("tsyhld", , xlFormulas, xlPart, , , False, False)).EntireRow.Delete
  Range(Cells.Find("ruleid", , xlFormulas, xlPart, , , False, False), Cells(Rows.Count, "A")).EntireRow.Delete
  On Error GoTo 0
End Sub

yes sir...you're a genius
 
Upvote 0
Does this macro do what you want...
Code:
Sub DeleteAboveTSYHLDandBelowRULEID()
  On Error Resume Next
  Range("A6", Cells.Find("tsyhld", , xlFormulas, xlPart, , , False, False)).EntireRow.Delete
  Range(Cells.Find("ruleid", , xlFormulas, xlPart, , , False, False), Cells(Rows.Count, "A")).EntireRow.Delete
  On Error GoTo 0
End Sub

actually seems to be one issue...it does delete the first "ruleID" below...but i should have mentioned that are more "ruleID" headers in the rows below....i need "ruleID" and EVERYTHING below it to be deleted
 
Upvote 0
actually seems to be one issue...it does delete the first "ruleID" below...but i should have mentioned that are more "ruleID" headers in the rows below....i need "ruleID" and EVERYTHING below it to be deleted
When you say everything below it, do you mean "in all columns"? If yes, how does that figure in with the other word (tsyhld) that you wanted to delete on?
 
Upvote 0
When you say everything below it, do you mean "in all columns"? If yes, how does that figure in with the other word (tsyhld) that you wanted to delete on?

here's what i mean:

Rich (BB code):
row 6

a
b
c


tsyhld

tsyinfo

ruleid


a
b

ruleid

a
b


i want row tsyhld deleted and everything ABOVE (including row 6)....want "tsyinfo" (multiple rows of information for tsyhld) to remain intact....want everything BELOW the tsyinfo deleted...when a new "ruleid" starts...it's no longer tsyinfo
 
Upvote 0
i want row tsyhld deleted and everything ABOVE (including row 6)....want "tsyinfo" (multiple rows of information for tsyhld) to remain intact....want everything BELOW the tsyinfo deleted...when a new "ruleid" starts...it's no longer tsyinfo
In your original message, you said "right now i look for "TSYHLD" and delete that row and all the rows it above until row 6". To the best of my understanding, that means Rows 1:5 remain untouched. As far as I can tell, my code does what you are asking for... Row 6 down to the row with "tsyhld" on it are deleted, the row with "ruleid" and all rows below it are deleted and the only thing that remains is Rows 1:5 and whatever rows were between (but not including) "tsyhld" and "ruleid". What is it that you think I am not doing?
 
Upvote 0
In your original message, you said "right now i look for "TSYHLD" and delete that row and all the rows it above until row 6". To the best of my understanding, that means Rows 1:5 remain untouched. As far as I can tell, my code does what you are asking for... Row 6 down to the row with "tsyhld" on it are deleted, the row with "ruleid" and all rows below it are deleted and the only thing that remains is Rows 1:5 and whatever rows were between (but not including) "tsyhld" and "ruleid". What is it that you think I am not doing?


exactly...but the code doesnt seem to delete eveyrhting below "ruleid".....as i tried to clarify, there are more than one "ruleid" below...i think the code just deletes the "first" ruleid it finds and all of its info...but doesnt delete the other "ruleids" below

Rich (BB code):
row 6

a
b
c


tsyhld

tsyinfo

ruleid


a
b

ruleid

a
b

ruleid

a
b

second ruleid doesnt get deleted
 
Upvote 0

Forum statistics

Threads
1,203,538
Messages
6,055,995
Members
444,839
Latest member
laurajames

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