0% found this document useful (0 votes)
105 views3 pages

Excel VBA Linear Coefficients

This document provides an Excel VBA macro that calculates linear correlation coefficients between two ranges of data entered by the user. The macro stores the linear coefficients in two cells on a new worksheet called "LinEst". It first checks if a sheet with that name already exists and deletes it. The macro then cites three references on Excel VBA and macros.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views3 pages

Excel VBA Linear Coefficients

This document provides an Excel VBA macro that calculates linear correlation coefficients between two ranges of data entered by the user. The macro stores the linear coefficients in two cells on a new worksheet called "LinEst". It first checks if a sheet with that name already exists and deletes it. The macro then cites three references on Excel VBA and macros.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Houston Seminar in Excel VBA Macros

Excel VBA Macro to calculate linear


correlation coefficients.

Sergio Perez Rodriguez


EG, PDG, MSc

July 2020
Sub Lin()

Dim varLinEst As Variant

Dim arg1, arg2 As Range

Set arg1 = Application.InputBox(Prompt:="Enter dependent variable data", Type:=8)

Set arg2 = Application.InputBox(Prompt:="Enter independent variable data", Type:=8)

varLinEst = WorksheetFunction.LinEst(arg1, arg2, True, True)

'This routine erases previous worksheets named LinEst

Dim ws As Worksheet

For Each ws In Worksheets

If ws.Name = "LinEst" Then

Application.DisplayAlerts = False

Sheets("LinEst").Delete

Application.DisplayAlerts = True

End

End If

Next

'Adding a worksheet named LinEst

Sheets.Add.Name = "LinEst"

Sheets("LinEst").Select

'Calculating and placing the linear coefficients in two cells of the new worksheet

Range("I3").Value = WorksheetFunction.Index(WorksheetFunction.LinEst(arg1, arg2), 1)

Range("J3").Value = WorksheetFunction.Index(WorksheetFunction.LinEst(arg1, arg2), 2)

End Sub
Bibliography

Jelen, B., Syrstad, T. 2016. Excel 2016 VBA and Macros. Pearson Education.

Roman, S. 2002. Writing Excel Macros with VBA. O’Reilly

Alexander, M. & Walkenbach, J. 2018. Excel VBA Programming For Dummies. Wiley

You might also like