FIND Select and Delete in Dynamic Range

Edgarvelez

Board Regular
Joined
Jun 6, 2019
Messages
197
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have 2 sheets
VBA Code:
    Set sh1 = Sheets("Intake Macro")
    Set sh2 = Sheets("UpLoad Sheet")

sh1 is where I have my buttons for the macros and other stuff
sh2 is where my data and final results go.

In sh2 I am trying to find and select the cell where the word "TOTAL" is and select 6 rows across and delete.
However if it does not find the word TOTAL then I want it to do nothing and continue.
The range of rows is dynamic.
I tried recording CTR-F and grabbing the code that way, but I am not at that level to alter the code if it does not find the word "TOTAL" to make it work.


sh2.JPG
 

Attachments

  • sh2.JPG
    sh2.JPG
    156.9 KB · Views: 1

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about
VBA Code:
Sub Edgarvelez()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Upload Sheet").UsedRange.Find("Total", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Fnd.Resize(, 6).ClearContents
End Sub
 
Upvote 0
I gave it a try and I increased the resize to 7, I think we are close.
VBA Code:
   Dim Fnd As Range
   
   Set Fnd = Sheets("Upload Sheet").UsedRange.Find("Total", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Fnd.Resize(, 7).ClearContents
I cant use ClearContents because the line has autosum and the format is different and when I run the code for the second time to add more rows things get a little out of format, I am think if we use select and then delete then that might work.

sh2.JPG
 
Upvote 0
Do you want to delete the entire row?
 
Upvote 0
if the line is deleted the when I run the code that puts all that data it will work.
I currently do it manually I select the whole row and then right click and Delete.
 
Upvote 0
In that case use
VBA Code:
If Not Fnd Is Nothing Then Fnd.EntireRow.Delete
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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