Rockhopper3
Board Regular
- Joined
- Apr 11, 2006
- Messages
- 131
Hello to all.
Have a quick one for everyone to mull over. To start, using Excel 2003 (don't say it, I already know ). I have a protected sheet with Autofilter boxes located from A4 to Y4. I need to be able to have a macro check the columns to see if any of the filters are active before saving, and if so deactivate them and go to the last cell with data in it in column A. If none of the columns have the auto filter on, just save as normal. I've worked out how to get it to work if a filter is engaged, but i get an error message if there are no filters engage and I try to save the file.
The other thing is that this code will not go to the cell below the last line of data (and I have used that part of the code in many other macros). Thanks in advance to everyone for you help and quick replies with this.
Rockhopper
Have a quick one for everyone to mull over. To start, using Excel 2003 (don't say it, I already know ). I have a protected sheet with Autofilter boxes located from A4 to Y4. I need to be able to have a macro check the columns to see if any of the filters are active before saving, and if so deactivate them and go to the last cell with data in it in column A. If none of the columns have the auto filter on, just save as normal. I've worked out how to get it to work if a filter is engaged, but i get an error message if there are no filters engage and I try to save the file.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Unprotect
ActiveSheet.ShowAllData
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True
Range("A" & lastrow).Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
The other thing is that this code will not go to the cell below the last line of data (and I have used that part of the code in many other macros). Thanks in advance to everyone for you help and quick replies with this.
Rockhopper