Deleting rows on multiple sheet

Giancar

Board Regular
Joined
Nov 29, 2017
Messages
52
Hi everyone,

I am trying without results to remove rows on multiple sheet.
First sheet is called FR, second is called IT and third is called ES.

I need to delete for each sheet, all the rows that have in column F (from F3 till the end of the table) a date before today.

Can you please help me?
Thank you in advance
 
I ran the macro on the file I attached several times and it worked properly without any errors. Did you try the file exactly as I attached it without making any changes to it? If so, what is the error that is displayed and does it error on the same line of code as before? What version of Excel are you using?
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
The error occurs because there is only 1 date later than today & Col J for that row then gets filtered out when you filter field 10. Hence no rows to copy
 
Upvote 0
I ran the macro on the file I attached several times and it worked properly without any errors. Did you try the file exactly as I attached it without making any changes to it? If so, what is the error that is displayed and does it error on the same line of code as before? What version of Excel are you using?

I am using Excel 2016 MSO 64 bit.

I have noticed that IT sheet has a different structure. If you check ES and FR, data are starting from 3rd row (header on 2nd row), but in IT is starting from 2nd row (header 1st row). Can be that one the reason?
 
Upvote 0
The error occurs because there is only 1 date later than today & Col J for that row then gets filtered out when you filter field 10. Hence no rows to copy

I ran the macro on the file I attached several times and it worked properly without any errors. Did you try the file exactly as I attached it without making any changes to it? If so, what is the error that is displayed and does it error on the same line of code as before? What version of Excel are you using?

I do not think is related to above problem.
Try to run to this updated version.
https://www.dropbox.com/s/yllvj68flc8k2x5/02-01(UPDATED VERSION).xlsx?dl=0

I have always the problem on the same line as before
 
Upvote 0
Click here to download the file. Have a look at the "IT GROUPS" sheet. That is what I get after I run the macro with no errors.
 
Upvote 0
Try this mod to mumps code
Code:
    Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & [COLOR=#0000ff]CLng(Date)[/COLOR]
I suspect that your local date form is DD/MM/YYYY, which will be turned to a US date format by the Autofilter
 
Upvote 0
My apologies. Try this link: https://app.box.com/s/amesp4uzolqokl2s7kbrzyehf2a2vz6u
If you still have problems, try Fluff's suggestion in Post# 27.

Try this mod to mumps code
Code:
    Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & [COLOR=#0000ff]CLng(Date)[/COLOR]
I suspect that your local date form is DD/MM/YYYY, which will be turned to a US date format by the Autofilter

Thank you Fluff, you are right, now Macro is working and give me the results I wished. I have made some corrections and now the Macro is the following:

Sub CopyRangeITOFF() Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Sheets("IT").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets("IT").Sort.SortFields.Clear
Sheets("IT").Sort.SortFields.Add Key:=Range("R1:R" & LastRow), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
Sheets("IT").Sort.SortFields.Add Key:=Range("S1:S" & LastRow), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With Sheets("IT").Sort
.SetRange Range("A1:AR" & LastRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=2, Criteria1:="Y"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=3, Criteria1:="1"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=10, Criteria1:=Array( _
"Trentino-Alto Adige", "Tuscany", "Emilia-Romagna", "Veneto", "Latium", "Lombardy"), Operator:=xlFilterValues
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="Hotel"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=10, Criteria1:=Array( _
"Sicily", "Aosta Valley", "Campania", "Liguria", "Basilicata", "Marches"), Operator:=xlFilterValues
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="Hotel"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=10, Criteria1:=Array( _
"Piedmont", "Apulia", "Umbria", "Abruzzo", "Sardinia", "Calabria"), Operator:=xlFilterValues
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="Hotel"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="Package"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=2, Criteria1:="Y"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=3, Criteria1:="1"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=7, Criteria1:=Array( _
"LONG_HAUL", "MIDDLE_HAUL"), Operator:=xlFilterValues
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="Hotel"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=6, Criteria1:=">=" & CLng(Date)
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=8, Criteria1:="HOTEL"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=7, Criteria1:="EUROPE"
Sheets("IT").Range("A1:AR" & LastRow).AutoFilter Field:=9, Criteria1:="<>Italy"
Sheets("IT").Range("A2:AR" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("IT GROUPS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("IT").AutoFilterMode = True Then Sheets("IT").AutoFilterMode = False
Application.ScreenUpdating = True
End Sub

But I need some further help :(
On top of each group that we "pasted" on the new sheet, I need to add 2 rows, the first one should be empty and then the second one of each group as following:

"DOM1" for the first group, "DOM2" for the second group, "DOM3" for the third group, "PKG" for the fourth group, "INT" for the fifth group and "EU" for the sixth.
Kindly check the following file. Sheet named "IT GROUPS FINAL" is what I am looking for.

As you are so good guys, I would like to have another Macro (not sure if this is possible to be honest). Please see the tab named "RANKING".
I would like to create a new sheet named "RANKING".
- Row 2 header
- A3:B38 is always looping till row 1010
- I would like Macro to extract the row of "IT GROUPS FINAL" of each category that is matching with the category in column B in ranking.
To be clearer: the 1st DOM1 in Column B of sheet "RANKING" needs to be the 1st row of group DOM1 in sheet "IT GROUP FINAL", the 1st PKG in Column B of sheet "RANKING" needs to be the 1st row of group PKG in sheet "IT GROUP FINAL", etc., etc.

Not sure if this is possible and how long it takes to do it. You already helped me a lot.

This as I would like the final result

https://www.dropbox.com/s/zoh2knza467py4r/02-01(final VERSION).xlsx?dl=0
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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