Forum

Delete rows with fo...
 
Notifications
Clear all

Delete rows with formulas no values

11 Posts
2 Users
0 Reactions
78 Views
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi,

I have statement for vendor the range is A17:I80, with column I containing formulas what I want VBA that deletes rows  after last used row in that range even though have formulas but no value.

I don't know much about VBA been searching internet without success cause all ones found just look for blanks because have formulas won't delete them.

 

Any suggestions,

 

Thank you

 
Posted : 22/09/2021 9:03 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Any help?

 

STATEMENT-SAMPLE.PNG

 

   

 
Posted : 23/09/2021 2:59 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Wow! no one can help. what a forum.

 
Posted : 25/09/2021 7:28 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Jose,

Posting a sample file will always help you get a faster result, otherwise we will have to recreate your structure and that will always be different than what you have.

Try this code:

Sub DeleteRows()

Dim Wks as worksheet, DeleteRng as range, i as long

Set Wks=ThisWorkbook.Worksheets("Sheet1")

For i=17 To 80

If LEN(Wks.Cells(i,"I").Value)=0 then

If DeleteRng is nothing then

Set DeleteRng=Wks.Cells(i,"I")

Else

Set DeleteRng=Union(DeleteRng,Wks.Cells(i,"I"))

End if

End If

Next i

If Not DeleteRng is Nothing then DeleteRng.EntireRow.Delete

End Sub

By the way, you could try searching our forum, you have solutions very close to your case:

https://www.google.com/search?q=delete+rows+site%3Amyonlinetraininghub.com&client=firefox-b-d&ei=7oJOYazyMPj87_UPhNqi6AE&oq=delete+rows+site%3Amyonlinetraininghub.com&gs_lcp=Cgdnd3Mtd2l6EAM6BwgAEEcQsANKBAhBGABQ7oYBWKWMAWDWjQFoAXACeACAAVGIAb8CkgEBNJgBAKABAcgBCMABAQ&sclient=gws-wiz&ved=0ahUKEwisoYHrg5nzAhV4_rsIHQStCB0Q4dUDCA0&uact=5

Welcome to our forum.

 
Posted : 25/09/2021 10:03 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

thank you.

 

I tried the code but getting compile error "invalid use of property".

 

attaching file.

 
Posted : 27/09/2021 10:41 pm
(@catalinb)
Posts: 1937
Member Admin
 

Nothing attached, you have to press the Start Upload button, after Select Files.

 
Posted : 28/09/2021 1:09 am
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi Catalin,

 

Attached now.

 

Thank you,

 
Posted : 28/09/2021 12:31 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Jose,

You did not copied the complete code as posted above, the delete method and the procedure closing statement is missing:

.Delete

End Sub

The code works if copied completely (and of course change Sheet1 to your sheet name - Statement).

 
Posted : 28/09/2021 10:56 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Thank you, Catalina.

 

Question,

If I want to change this:

 

For i=17 To 80 to a name range instead like "STMTRNG"  how do I do it?

 

Sorry to ask stupid question but that good in VBA.

 

Thanks again.

 
Posted : 29/09/2021 12:42 am
(@catalinb)
Posts: 1937
Member Admin
 

Not tested, but should work:

For i=wks.range("STMTRNG").cells(1).row to (wks.range("STMTRNG").cells(1).row + wks.range("STMTRNG").Rows.Count)

 
Posted : 29/09/2021 1:58 am
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Thank you so much, Catalin.

 

worked perfectly!.

 
Posted : 29/09/2021 7:32 pm
Share: