Macro to delete unnecessary rows and sort the rest

mac_see

Active Member
Joined
Oct 15, 2002
Messages
419
Book3
ABCDEFGHIJKL
1A10.00%C180.00%C86.96
22B375.00%B13.04
33B225.00%
4B113.04%C315.00%
5225.00%C25.00%
6375.00%
7C186.96%80.00%
825.00%
9315.00%
10
Sheet1


I need a macro that can eliminate rows where figures in column D are blank and then sort the rest of the rows based on column D and put the result in column F:H

Similarly, eliminate rows where figures in column C are blank and then sort the rest of the rows based on column C and put the result in coumn J:K

There are merged cells which I cannot unmerge. The above is just an example, If I read and understand the logic behind the macro, I can manipulate it and use it for my data

Thanx
Maxi
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Maxi

Hopefully this will get you going.

Code:
Sub bbb()
 lastrow = Cells(Rows.Count, "B").End(xlUp).Row
 Range("A1:A" & lastrow).SpecialCells(xlCellTypeBlanks).Formula = "=A1"
 Range("A1:A" & lastrow).Value = Range("a1:a" & lastrow).Value
 Range("D1:D" & lastrow).Copy Destination:=Range("H1")
 Range("H1:H" & lastrow).Sort key1:=Range("H1"), order1:=xlDescending, header:=xlNo
 For Each ce In Range("H1").CurrentRegion
  ce.Offset(0, -1).Value = Evaluate("=Index(B:B,Match(" & ce.Value & ", D:D, 0))")
  ce.Offset(0, -2).Value = Evaluate("=Index(A:A,Match(" & ce.Value & ", D:D, 0))")
 Next ce

 Range("C1:C" & lastrow).Copy Destination:=Range("K1")
 Range("K1:K" & lastrow).Sort key1:=Range("K1"), order1:=xlDescending, header:=xlNo
 For Each ce In Range("K1").CurrentRegion
  ce.Offset(0, -1).Value = Evaluate("=Index(A:A,Match(" & ce.Value & ", C:C, 0))")
 Next ce
End Sub

Tony
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,730
Members
449,465
Latest member
TAKLAM

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