Hi everyone. So one of my coworkers asked me to update a macro that she uses for checking to see what assignments students turned in. Previously, she had a specific template that was never edited; however, she now wants to be able to still run the macro if a specific column is removed or one is added (adding would be a nice to have, but not required). I now have to make the macro more dynamic. Here's an example of what I'm trying to accomplish with the macro.
Before the macro is run.
After the macro is run.
Again, the macro does work when columns aren't removed/added, but now she wants to have the ability to remove Math, History, and Science columns without issue. Right now, if a column is deleted, it would count whatever data is in column O. For example, if Science Grade 3 is removed, Finalized would be counted in Clark, Diana, and Bruce's Science counts. It's hard coded to only work for
Here's the current code:
My initial thought was to only look for numerical values, using isNumerical, but my macro crashes when I try. My other thought was to code the macro to only search rows that are underneath a specific column name that contains Math, History, or Science in the cell, but I haven't had any luck figuring out how to do that. Any help would greatly be appreciated. Thank you.
Before the macro is run.
After the macro is run.
Again, the macro does work when columns aren't removed/added, but now she wants to have the ability to remove Math, History, and Science columns without issue. Right now, if a column is deleted, it would count whatever data is in column O. For example, if Science Grade 3 is removed, Finalized would be counted in Clark, Diana, and Bruce's Science counts. It's hard coded to only work for
Here's the current code:
Excel Formula:
Sub CreateMap()
Dim TempString As String
TempString = ""
Application.ScreenUpdating = False ' Ensure we aren't spamming the graphics engine
Dim TheLastRow As Long
TheLastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
' Insert the columns for the Math, History and Science maps
Columns("G:G").Select
Selection.Insert Shift:=xlToRight ', CopyOrigin:=xlFormatFromLeftOrAbove
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("I:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Insert the all-data-indicator formulas for the Math formats
Columns("G:G").Select
TempString = "IF(RC[4]>0,""1,"","""")&IF(RC[7]>0,""2,"","""")&IF(RC[10]>0,""3,"","""")"
Selection.FormulaR1C1 = "=IF(LEN(" + TempString + ") > 0, LEFT( " + TempString + ", LEN( " + TempString + " ) - 1 ), " + TempString + " )"
Columns("G:G").EntireColumn.AutoFit
Columns("G:G").Formula = Columns("G:G").Value
Range("G1").Select
ActiveCell.FormulaR1C1 = "Math Map"
' Insert the all-data-indicator formulas for the History formats
Columns("H:H").Select
TempString = "IF(RC[4]>0,""1,"","""")&IF(RC[7]>0,""2,"","""")&IF(RC[10]>0,""3,"","""")"
Selection.FormulaR1C1 = "=IF(LEN(" + TempString + ") > 0, LEFT( " + TempString + ", LEN( " + TempString + " ) - 1 ), " + TempString + " )"
Columns("H:H").EntireColumn.AutoFit
Columns("H:H").Formula = Columns("H:H").Value
Range("H1").Select
ActiveCell.FormulaR1C1 = "History Map"
' Insert the all-data-indicator formulas for the Science formats
Columns("I:I").Select
TempString = "IF(RC[4]>0,""1,"","""")&IF(RC[7]>0,""2,"","""")&IF(RC[10]>0,""3,"","""")"
Selection.FormulaR1C1 = "=IF(LEN(" + TempString + ") > 0, LEFT( " + TempString + ", LEN( " + TempString + " ) - 1 ), " + TempString + " )"
Columns("I:I").EntireColumn.AutoFit
Columns("I:I").Formula = Columns("I:I").Value
Range("I1").Select
ActiveCell.FormulaR1C1 = "Science Map"
' Draw borders around the maps, and shade/color the cells
Call HighlightAllGradeMaps(TheLastRow)
' Draw the legend at the top
Call DrawInstructions("AllGrade")
ActiveSheet.name = "All Grade Map"
' If we aren't already filtering, then turn it on
If ActiveSheet.AutoFilterMode = False Then
[a3].Select
Selection.AutoFilter
End If
Rows("1:1").Select
Selection.Activate
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
Rows("1:1").Select
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
End Sub
My initial thought was to only look for numerical values, using isNumerical, but my macro crashes when I try. My other thought was to code the macro to only search rows that are underneath a specific column name that contains Math, History, or Science in the cell, but I haven't had any luck figuring out how to do that. Any help would greatly be appreciated. Thank you.