Help creating a macro that will remove space between blank rows. Keep getting "Cannot use that command on overlapping selections" error

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create a micro that will let me delete blank rows between data in order to be able to sort and filter.

View attachment 53209

I would like for the macro to delete a row whenever it notices a blank column on the row. After that I would like for the worksheet to be sorted by column D then column A then column G.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Do you mean Rows 12, 13, 19, 20, 21 and 22 in your picture?
 
Upvote 0
How about
VBA Code:
Sub Coyotex()
  Range("B1", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Coyotex()
  Range("B1", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
This sub is absolutely amazing. I can't believe Excel is so powerful and I imagine I'm barely scratching the surface. This code works but I can't get the sort portion right. Here is what I have


Sub Macro10()
'
' Macro10 Macro
'

'
ActiveWorkbook.Worksheets("Sheet1 (17)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1 (17)").Sort.SortFields.Add2 Key:=ActiveCell _
.Offset(0, 3).Range("A1:A147"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1 (17)").Sort.SortFields.Add2 Key:=ActiveCell _
.Range("A1:A147"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1 (17)").Sort
.SetRange ActiveCell.Offset(-1, 0).Range("A1:G148")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

I'm trying to make my next command on the chain to sort by column D and then Column A. My code is not working though.
 
Upvote 0
Try
VBA Code:
  Range("A1").CurrentRegion.Sort Range("D1"), xlAscending, Range("A1"), , xlAscending, Header:=xlYes
 
Upvote 0
Glad we could help & thanks for the feedback.
 
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