Hi all,
I am using excel 2003. I'm currently stuck at this problem. Situation is, i'm working to improve an excel database right now. When users use the file, they click on buttons and the buttons lead them to a filtered view of the database.
Previously, the code of the button goes like this in general:
Sheets("Main") = User interface where user clicks on buttons
Sheets("MasterList") = Database
Sheets("MasterList").Visible = True
Sheets("Main").Visible = False
Sheets("MasterList").Select
Rows("2:1000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Country"
Selection.AutoFilter Field:=17, Criteria1:="Address"
Selection.Sort Key1:=Range("P3"), Order1:=xlDescending, Key2:=Range("B3"), Order2:=xlAscending, Key3:=Range("C3"), Order3:=xlAscending, Header:= xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= xlSortNormal
Columns("S").Select
Selection.EntireColumn.Hidden = True
Columns("U:Z").Select
Selection.EntireColumn.Hidden = True
Columns("AC:AZ").Select
Selection.EntireColumn.Hidden = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A2").Select
So users would go ahead to add, delete, update whatever they want to. Users who want to add new records would click on a 'Add New Record' button. The button will then lead the users to a blank page.
Now here's where the problem comes. When users add new records by clicking on the 'Add New Record' button, the records get updated neatly. (If the last record was Row 3, the inserted record will be at Row 4)
However, some users are lazy to do so, and just insert a new record without clicking on the 'Add New Record' button. Thus their record's number starts with Row number 1000.
Attempting to solve that problem, i changed the codes of the buttons in the user interface to the following:
Sheets("MasterList").Visible = True
Sheets("Main").Visible = False
Sheets("MasterList").Select
TotalRow = Rows.Count
Rows("2:" & TotalRow).Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Acc Opening"
Selection.AutoFilter Field:=17, Criteria1:="Completed"
Selection.Sort Key1:=Range("P3"), Order1:=xlDescending, Key2:=Range("B3") , Order2:=xlAscending, Key3:=Range("C3"), Order3:=xlAscending, Header:= xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= xlSortNormal
Columns("S").Select
Selection.EntireColumn.Hidden = True
Columns("U:Z").Select
Selection.EntireColumn.Hidden = True
Columns("AC:AZ").Select
Selection.EntireColumn.Hidden = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A2").Select
It seemed to work fine at first. After the last row of records would be grey space. (Just like after row 65536) But then, i had a new requirement for the system, i'm tasked to allow users to view the records in a 'Form' mode. Thus, i'm now trying to insert new records via the default excel form mode. But after i do so, the records appear at row number 1000+ again instead of the row right after the last record! Even after i changed the codes! I really do not know what is happening. Please advice me.
Thank you!
I am using excel 2003. I'm currently stuck at this problem. Situation is, i'm working to improve an excel database right now. When users use the file, they click on buttons and the buttons lead them to a filtered view of the database.
Previously, the code of the button goes like this in general:
Sheets("Main") = User interface where user clicks on buttons
Sheets("MasterList") = Database
Sheets("MasterList").Visible = True
Sheets("Main").Visible = False
Sheets("MasterList").Select
Rows("2:1000").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Country"
Selection.AutoFilter Field:=17, Criteria1:="Address"
Selection.Sort Key1:=Range("P3"), Order1:=xlDescending, Key2:=Range("B3"), Order2:=xlAscending, Key3:=Range("C3"), Order3:=xlAscending, Header:= xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= xlSortNormal
Columns("S").Select
Selection.EntireColumn.Hidden = True
Columns("U:Z").Select
Selection.EntireColumn.Hidden = True
Columns("AC:AZ").Select
Selection.EntireColumn.Hidden = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A2").Select
So users would go ahead to add, delete, update whatever they want to. Users who want to add new records would click on a 'Add New Record' button. The button will then lead the users to a blank page.
Now here's where the problem comes. When users add new records by clicking on the 'Add New Record' button, the records get updated neatly. (If the last record was Row 3, the inserted record will be at Row 4)
However, some users are lazy to do so, and just insert a new record without clicking on the 'Add New Record' button. Thus their record's number starts with Row number 1000.
Attempting to solve that problem, i changed the codes of the buttons in the user interface to the following:
Sheets("MasterList").Visible = True
Sheets("Main").Visible = False
Sheets("MasterList").Select
TotalRow = Rows.Count
Rows("2:" & TotalRow).Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Acc Opening"
Selection.AutoFilter Field:=17, Criteria1:="Completed"
Selection.Sort Key1:=Range("P3"), Order1:=xlDescending, Key2:=Range("B3") , Order2:=xlAscending, Key3:=Range("C3"), Order3:=xlAscending, Header:= xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= xlSortNormal
Columns("S").Select
Selection.EntireColumn.Hidden = True
Columns("U:Z").Select
Selection.EntireColumn.Hidden = True
Columns("AC:AZ").Select
Selection.EntireColumn.Hidden = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A2").Select
It seemed to work fine at first. After the last row of records would be grey space. (Just like after row 65536) But then, i had a new requirement for the system, i'm tasked to allow users to view the records in a 'Form' mode. Thus, i'm now trying to insert new records via the default excel form mode. But after i do so, the records appear at row number 1000+ again instead of the row right after the last record! Even after i changed the codes! I really do not know what is happening. Please advice me.
Thank you!