excelbytes
Active Member
- Joined
- Dec 11, 2014
- Messages
- 298
- Office Version
- 365
- Platform
- Windows
I have a Table called Table1. The headers are in row 2, the data starts in row 3. In A1 is an Active X Combo Box that uses the names in the first column of the table ("Members") as it's list and the linked cell is behind it in A1. The worksheet has certain columns that are protected because of formulas in the table. To insert a rows, I use this code that will unprotect the sheet, add a row then re-protect it:
Sub AddRow()
ActiveSheet.Unprotect Password:="paul"
Range("A1").End(xlDown).ListObject.ListRows.Add AlwaysInsert:=False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="paul"
End Sub
After I add name(s), I need to resort it, and I use this code:
Sub SortMembers()
'
' SortMembers Macro
ActiveSheet.Unprotect Password:="paul"
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1"). _
Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1"). _
Sort.SortFields.Add2 Key:=Range("Table1[Members]"), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1" _
).Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="paul"
End Sub
I have conditional formatting that will highlight the rows of the table based on the choice of the Active X Combo Box. The range in Conditional Formatting does auto adjust when I add rows. The formula for the conditional formatting is:
=$A3=$A$1
The problem is that when I sort the table using the VBA code, the conditional formatting doesn't work unless I go into Conditional Formatting and Manage the formula by just touching it. Everything does work normally when I add rows and sort it manually when the sheet is not protected. Is there something in my code that is causing this problem?
Sub AddRow()
ActiveSheet.Unprotect Password:="paul"
Range("A1").End(xlDown).ListObject.ListRows.Add AlwaysInsert:=False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="paul"
End Sub
After I add name(s), I need to resort it, and I use this code:
Sub SortMembers()
'
' SortMembers Macro
ActiveSheet.Unprotect Password:="paul"
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1"). _
Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1"). _
Sort.SortFields.Add2 Key:=Range("Table1[Members]"), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Individual Contributions").ListObjects("Table1" _
).Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="paul"
End Sub
I have conditional formatting that will highlight the rows of the table based on the choice of the Active X Combo Box. The range in Conditional Formatting does auto adjust when I add rows. The formula for the conditional formatting is:
=$A3=$A$1
The problem is that when I sort the table using the VBA code, the conditional formatting doesn't work unless I go into Conditional Formatting and Manage the formula by just touching it. Everything does work normally when I add rows and sort it manually when the sheet is not protected. Is there something in my code that is causing this problem?