Hey all, I am working on a spreadsheet for work that has 3 macros built in. One adds a line of data to a chart from one sheet ("Wind on small elements") to another sheet ("Results"), another clears this chart and the last displays an image based on what is selected in a validated list from one cell. The problem I am having is with the third macro.
Using Worksheet_calculate() to trigger the macro, it works, but it runs everytime any calculation is done. Is there a way I can stop this?
It also initially made the other two macros not work until I added a little bit of code to fix it (in bold). It's not the most elegant of solutions as it only solved one of the problems and the screen flashes between sheets a bit more than it should. Is there a way around this?
I don't have access to my spreadsheet, since it is something I am doing for work, but my code is:
Private Sub CommandButton1_Click()
x = Range("L10").Value
Range("I8:O8").Copy
Sheets("Results").Select
Sheets("Results").Cells(x, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
x = Range("L10") + 1
Range("L10") = x
Sheets("Results").Select
End Sub
Private Sub CommandButton2_Click()
Sheets("Results").Select
Sheets("Results").Range("A2:G50").Select
Selection.ClearContents
Sheets("Wind on small Elements").Select
Range("L10").Select
ActiveCell.FormulaR1C1 = "2"
End Sub
Private Sub Worksheet_calculate()
Sheets("Wind on small Elements").Select
If Range("P42") = "Commentary I Figure I-9 (<7°)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig9").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-11 (7 - 27° gabled)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig11a").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-11 (27 - 45° gabled)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig11b").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-12 (10 - 30° gabled)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig12a").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-12 (30 - 45° gabled)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig12b").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-13 (3 - 10°)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig13a").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-13 (10 - 30°)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig13b").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
ElseIf Range("P42") = "Commentary I Figure I-14 (10 - 30°)" Then
ActiveSheet.Shapes("Rectangle 1137").Select
Selection.ShapeRange.ZOrder msoBringToFront
ActiveSheet.Shapes("Fig14").Select
Selection.ShapeRange.ZOrder msoBringToFront
Exit Sub
End If
End Sub
Bookmarks