Monicasinha
Board Regular
- Joined
- Dec 26, 2022
- Messages
- 51
- Office Version
- 365
- Platform
- Windows
Hi
I am using the below VBA code. This is for updating charts, formatting, adding data labels.
It is taking long time to process. Can you please help.
----------------------------------------------------------------------------------------------------------------------------------------------
Sub ColorByCategoryLabel()
Dim x As Integer
Dim varValues As Variant
Dim iCategory As Long
Dim rCategory As Range
Dim Series As Long
Dim i As Long
Dim labelStr As String
Dim saveAsFilename As String
Dim ErrorMessage As String
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
For y = 111 To 121
RH = 14
If .Cells(y, 63) <= 0 Then RH = 0
.Cells(y, 63).RowHeight = RH
Next y
End With
Set cht = ActiveSheet.ChartObjects("AChart").Chart
For ISeries = 1 To 6
With cht.SeriesCollection(ISeries)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
Select Case ISeries
Case 1, 5, 6
.Points(x).Interior.ColorIndex = xlNone
End Select
Next
End With
Next
With cht.SeriesCollection(3)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "CR" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS2").Interior.Color
ElseIf varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS2").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS3").Interior.Color
Else: .Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS3").Interior.Color
End If
Next
End With
With cht.SeriesCollection(2)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS4").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS5").Interior.Color
With .Points(x).Format.Fill
.Patterned msoPatternWideUpwardDiagonal
End With
End If
Next
End With
With cht.SeriesCollection(4)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS6").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS5").Interior.Color
With .Points(x).Format.Fill
.Patterned msoPatternWideUpwardDiagonal
End With
End If
Next
End With
With cht.SeriesCollection(3)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
saveAsFilename = Environ("temp") & "\temp.png"
If Not ExportImage(saveAsFilename, ActiveSheet.Shapes("Diamond 1"), ErrorMessage) Then
MsgBox ErrorMessage, vbCritical, "Error"
Exit Sub
End If
If varValues(x) = "B Price (per CTA)" Then
With .Points(x).Format.Fill
.Visible = msoTrue
.UserPicture saveAsFilename
.TextureTile = msoFalse
Kill saveAsFilename
End With
End If
saveAsFilename = Environ("temp") & "\temp.png"
If Not ExportImage(saveAsFilename, ActiveSheet.Shapes("Star 1"), ErrorMessage) Then
MsgBox ErrorMessage, vbCritical, "Error"
Exit Sub
End If
If varValues(x) = "Client Budget" Then
With .Points(x).Format.Fill
.Visible = msoTrue
.UserPicture saveAsFilename
.TextureTile = msoFalse
Kill saveAsFilename
End With
End If
With cht.SeriesCollection(3)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(3).Points(x).HasDataLabel = _
True
cht.SeriesCollection(3).Points(x).DataLabel.Text = "Standard"
cht.SeriesCollection(3).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(3).Points(x).HasDataLabel = _
True
cht.SeriesCollection(3).Points(x).DataLabel.Text = "50th"
cht.SeriesCollection(3).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
With cht.SeriesCollection(2)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(2).Points(x).HasDataLabel = _
True
cht.SeriesCollection(2).Points(x).DataLabel.Text = "Invested"
cht.SeriesCollection(2).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(2).Points(x).HasDataLabel = _
True
cht.SeriesCollection(2).Points(x).DataLabel.Text = "25th"
cht.SeriesCollection(2).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
With cht.SeriesCollection(4)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(4).Points(x).HasDataLabel = _
True
cht.SeriesCollection(4).Points(x).DataLabel.Text = "Differentiated"
cht.SeriesCollection(4).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(4).Points(x).HasDataLabel = _
True
cht.SeriesCollection(4).Points(x).DataLabel.Text = "75th"
cht.SeriesCollection(4).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
Next
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
I am using the below VBA code. This is for updating charts, formatting, adding data labels.
It is taking long time to process. Can you please help.
----------------------------------------------------------------------------------------------------------------------------------------------
Sub ColorByCategoryLabel()
Dim x As Integer
Dim varValues As Variant
Dim iCategory As Long
Dim rCategory As Range
Dim Series As Long
Dim i As Long
Dim labelStr As String
Dim saveAsFilename As String
Dim ErrorMessage As String
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
For y = 111 To 121
RH = 14
If .Cells(y, 63) <= 0 Then RH = 0
.Cells(y, 63).RowHeight = RH
Next y
End With
Set cht = ActiveSheet.ChartObjects("AChart").Chart
For ISeries = 1 To 6
With cht.SeriesCollection(ISeries)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
Select Case ISeries
Case 1, 5, 6
.Points(x).Interior.ColorIndex = xlNone
End Select
Next
End With
Next
With cht.SeriesCollection(3)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "CR" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS2").Interior.Color
ElseIf varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS2").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS3").Interior.Color
Else: .Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS3").Interior.Color
End If
Next
End With
With cht.SeriesCollection(2)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS4").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS5").Interior.Color
With .Points(x).Format.Fill
.Patterned msoPatternWideUpwardDiagonal
End With
End If
Next
End With
With cht.SeriesCollection(4)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
If varValues(x) = "B SD²" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS6").Interior.Color
ElseIf varValues(x) = "MR³" Then
.Points(x).Format.Fill.ForeColor.RGB = ActiveSheet.Range("BS5").Interior.Color
With .Points(x).Format.Fill
.Patterned msoPatternWideUpwardDiagonal
End With
End If
Next
End With
With cht.SeriesCollection(3)
varValues = .XValues
For x = LBound(varValues) To UBound(varValues)
saveAsFilename = Environ("temp") & "\temp.png"
If Not ExportImage(saveAsFilename, ActiveSheet.Shapes("Diamond 1"), ErrorMessage) Then
MsgBox ErrorMessage, vbCritical, "Error"
Exit Sub
End If
If varValues(x) = "B Price (per CTA)" Then
With .Points(x).Format.Fill
.Visible = msoTrue
.UserPicture saveAsFilename
.TextureTile = msoFalse
Kill saveAsFilename
End With
End If
saveAsFilename = Environ("temp") & "\temp.png"
If Not ExportImage(saveAsFilename, ActiveSheet.Shapes("Star 1"), ErrorMessage) Then
MsgBox ErrorMessage, vbCritical, "Error"
Exit Sub
End If
If varValues(x) = "Client Budget" Then
With .Points(x).Format.Fill
.Visible = msoTrue
.UserPicture saveAsFilename
.TextureTile = msoFalse
Kill saveAsFilename
End With
End If
With cht.SeriesCollection(3)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(3).Points(x).HasDataLabel = _
True
cht.SeriesCollection(3).Points(x).DataLabel.Text = "Standard"
cht.SeriesCollection(3).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(3).Points(x).HasDataLabel = _
True
cht.SeriesCollection(3).Points(x).DataLabel.Text = "50th"
cht.SeriesCollection(3).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
With cht.SeriesCollection(2)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(2).Points(x).HasDataLabel = _
True
cht.SeriesCollection(2).Points(x).DataLabel.Text = "Invested"
cht.SeriesCollection(2).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(2).Points(x).HasDataLabel = _
True
cht.SeriesCollection(2).Points(x).DataLabel.Text = "25th"
cht.SeriesCollection(2).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
With cht.SeriesCollection(4)
If varValues(x) = "B SD²" Then
cht.SeriesCollection(4).Points(x).HasDataLabel = _
True
cht.SeriesCollection(4).Points(x).DataLabel.Text = "Differentiated"
cht.SeriesCollection(4).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
ElseIf varValues(x) = "MR³" Then
cht.SeriesCollection(4).Points(x).HasDataLabel = _
True
cht.SeriesCollection(4).Points(x).DataLabel.Text = "75th"
cht.SeriesCollection(4).Points(x).DataLabel.Font.Color = RGB(0, 0, 0)
End If
End With
Next
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub