Excel VBA: How to create a dynamic skyline chart

Cakz Primz

Board Regular
Joined
Dec 4, 2016
Messages
102
Office Version
  1. 365
Platform
  1. Windows
Dear folks,

I have a code that taken from internet to create/generate a skyline.
The data source is coming from "System" sheet and it will generate a skyline chart into "Skyline" sheet.
So far the code is working fine.

Below is the code that generating skyline:
VBA Code:
Option Explicit
Option Private Module
Public skydate As Range
Public axisy As Integer
Public interval As Long
Public skyrange As Range
Public skycell As Range
Public plan As Range
Public y As Integer
Public fs As Integer

VBA Code:
Sub generate()



With Range("skylinearea")
    .Clear
    .Interior.Color = Range("skylineareabg").Interior.Color
    .Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Borders(xlEdgeBottom).LineStyle = xlContinuous
    With .Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Color = Range("skylineareabg").Offset(0, 1).Interior.Color
    End With
End With
On Error Resume Next

For Each skydate In Range("skylinedate")

    interval = skydate - skydate.Offset(0, -1)
    If Err.Number > 0 Then
        interval = skydate.Offset(0, 1) - skydate
    End If
    Err.Clear

    axisy = Range("skylinearea").Rows(Range("skylinearea").Rows.Count).Columns(1).Row

    For y = 1 To Range("listplan").Rows.Count
        Set plan = Range("listplan").Rows(y)
        Set skycell = Sheet1.Cells(axisy, skydate.Column)
        If ActiveSheet.Shapes("check2").ControlFormat.Value = 1 And Range("listcomp").Rows(y).Value = "OK" Then
            If plan <= skydate And plan > (skydate - interval) Then
                skycell = Range("listsystem").Rows(y)
                axisy = axisy - 1
                Call formatting
            End If
        End If
        If Range("listcomp").Rows(y).Value <> "OK" Then
            If plan <= skydate And plan > (skydate - interval) Then
                skycell = Range("listsystem").Rows(y)
                axisy = axisy - 1
                Call formatting
            End If
        End If
    Next
Next

Range("skylinearea").Select

End Sub

VBA Code:
Sub formatting()

fs = Range("fontsize").Value

With skycell
    .Hyperlinks.Add anchor:=skycell, Address:="", SubAddress:=skycell.Address, ScreenTip:="Click for more detail"
    .Interior.Color = Range(Range("liststatus").Rows(y)).Interior.Color
    .Interior.Pattern = Range(Range("liststatus").Rows(y)).Interior.Pattern
    .Interior.PatternColor = Range(Range("liststatus").Rows(y)).Interior.PatternColor
    .Font.Color = Range(Range("liststatus").Rows(y)).Font.Color
    .Font.Underline = xlUnderlineStyleNone
    .Font.Bold = True
    .Font.Size = fs
    .WrapText = True
    .HorizontalAlignment = xlCenter
    With .Borders
        .LineStyle = xlContinuous
        .Color = Range(Range("liststatus").Rows(plan.Row - Range("liststatus").Row + 1)).Offset(0, 1).Interior.Color
    End With
End With

End Sub


But then, my boss wants to see skyline based on certain criteria on column C (RFSU) in "System" sheet.
And I do not know how to generate a dynamic skyline chart in VBA.
I wish and hope that anybody can help me.

Thank you very much in advance, for your kind attention and help.
Prima - Indonesia

Link:
Dynamic SH1 Skyline Overall 20230227 (CPY).xlsm

Dynamic SH1 Skyline Overall 20230227 (CPY).xlsm
E
236CCTV - Security Control Room - Offsite Area
System
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D5:E508Cell ValueduplicatestextNO
 

Attachments

  • criteria.png
    criteria.png
    71.5 KB · Views: 27

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Dear RoryA,

I am really sorry

Next time it won't happen again
Thank you very much for the warning.

Best regards,
prima
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Dear RoryA,

I am really sorry

Next time it won't happen again
Thank you very much for the warning.

Best regards,
prima
And so far, until now I am not opening/reading the post in Chandoo.
And I will not opening again for more.

Thank you
prima - Indonesia
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top