Auto remove row depending on cell value

XpbX

New Member
Joined
Nov 4, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi, I am working on a worksheet for our sale rep, with list of equipment which the macro removes all the rows that has no Qty in it
So far I use this:

Dim lastrow As Long, r As Long

lastrow = Cells(Rows.Count, "G").End(xlUp).Row

For r = 195 To 14 Step -1
If Cells(r, "c") = 0 Then
Rows(r).EntireRow.Delete
End If
Next r

Which I copied from one thread here and adapted it to my needs. ( I have to admit I don't understand the whole thing though)

It works fine, Qty is in column C, and it deletes everything that needs to be gone,

My main problem is that at the end of all the items there is notes and sales stuff and I which I could start removing not from a row number but from a certain cell I call "end" for now. Which is between the items and the sales notes.
I want the reps to be able to redo the macro that deletes row if they adjust values (as they often renew contracts with some items not needed to be charged again)

So basically, my question is how can we remove rows starting from a row that is not a fixed row number? but based on a cell value
is this even possible.
Thank you for your help.
 

Attachments

  • Capture.PNG
    Capture.PNG
    27.1 KB · Views: 12
How can you loop from "Estimate" to 14?

The way you have written the code, you are telling it to take whatever is in cell A1 and loop from that number down to 14.
So if you do not have a number in cell A1, it will not work.

I think you are a bit confused, so let's take a few steps back here for a minute.
Your ending row is dynamic (meaning that you cannot hard-code it, as it changes).
That means we must come up with a dynamic solution.

So we have a few options:
1. To pull from a variable somewhere
- It can be a cell, like A1, but that means that cell always has to contain the correct value). Typically, this would be some sort of formula/calculation in the cell.
- It can be a variable that is calculation in VBA
2. To dynamically tell it to start from the last populated cell in some particular column. If you choose to go this route, you MUST choose a column that will always be populated for data. in every row that you want your loop to hit.

So, if you can just explain, in plain English the "logic" you want us to use to dynamically locate which is the last row to use in the loop, we can help you with that.
But w need you to clearly provide that information to us.
Eureka!!!

What I did is instead of looking to last row on row C, It will look in row J, where there is never anything written there in the last section.

Thanks for your help sir!
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You are welcome.
Glad we got it figure out.
:)
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

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