Advanced Data Analysis Advanced

Correlation Analysis

Calculate correlations between different data series

15 views

Perfect For:

  • Financial analysis
  • Market research
  • Performance correlation
VBA Code
Sub CalculateCorrelations()
    Dim ws As Worksheet
    Dim xRange As Range, yRange As Range
    Dim correlation As Double
    Dim lastRow As Long

    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row

    ' Define data ranges
    Set xRange = ws.Range("A2:A" & lastRow)
    Set yRange = ws.Range("B2:B" & lastRow)

    ' Calculate correlation
    correlation = Application.WorksheetFunction.Correl(xRange, yRange)

    ' Output results
    ws.Range("D1").Value = "Correlation Analysis"
    ws.Range("D2").Value = "Correlation: " & Round(correlation, 4)

    ' Interpret correlation strength
    Select Case Abs(correlation)
        Case Is >= 0.7
            ws.Range("D3").Value = "Strong correlation"
        Case Is >= 0.3
            ws.Range("D3").Value = "Moderate correlation"
        Case Else
            ws.Range("D3").Value = "Weak correlation"
    End Select

    MsgBox "Correlation analysis complete! R = " & Round(correlation, 4)
End Sub

Related Topics

correlation statistics analysis relationships

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code

Related Templates

More VBA templates in the same category

Intermediate

ROI Calculator with Scenarios

Calculate Return on Investment with multiple scenario analysis

View Template
Advanced

Advanced Data Analysis

Statistical analysis and data validation

View Template