Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:57:46+00:00 2026-06-11T04:57:46+00:00

Sub testCov() Rng2 = Sheets(20 Asset Model).Range(b3:f48) Dim covMatrix() As Variant ReDim covMatrix(1 To

  • 0
Sub testCov()
    Rng2 = Sheets("20 Asset Model").Range("b3:f48")
    Dim covMatrix() As Variant
    ReDim covMatrix(1 To Rng2.Columns.Count, 1 To Rng2.Columns.Count)
    Call constructCovMatrix(Rng2, covMatrix)
    MsgBox (covMatrix)
End Sub

Sub constructCovMatrix(rng, ByRef covMatrix)
    '@rng The Range of the return series.

    Dim i As Integer
    Dim j As Integer
    For i = 1 To rng.Columns.Count
        For j = 1 To rng.Columns.Count
            covMatrix(i, j) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j))
        Next
    Next
End Sub

The code stops at the line ReDim, saying object missing. Why is this? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:57:48+00:00Added an answer on June 11, 2026 at 4:57 am

    Try this to set your range as a range object be declaring it: (comments in-line)

    Sub testCov()
    
        Dim Rng2 As Range '- Declare variable
        Set Rng2 = Sheets("20 Asset Model").Range("b3:f48") '-Set range
        Dim covMatrix() As Variant
        ReDim covMatrix(1 To Rng2.Columns.Count, 1 To Rng2.Columns.Count)
        Call constructCovMatrix(Rng2, covMatrix)
        MsgBox (covMatrix)
    
        Set Rng2 = Nothing '- Cleanup anytime 'Set' is used
    End Sub
    

    Note:

    You may want to go to the VBA editor’s setting sand click tools > options > Declare varible decleration > checked

    This will ensure that you need to declare all your variables.

    As is, the above code did not declare Rng2 as a range. So when Excel first sees the name Rng2 it creates a Variant type variable and sets it equal to the range of the sheet in the first line. Excel notices that Sheets("20 Asset Model").Range("b3:f48") is an array of cells, and it treats the variant Rng2 as an array type variable going forward for the rest of your code. Assuming that you want to use the variable named Rng2 as a range, we can declare it as such and use the Set command to assign it.

    When you don’t declare your variable types its easy for a mix-up like this to happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sub StoragevsQuota() Charts.Add ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData Source:=Sheets(Data).Range(E1:G32) ActiveChart.Location Where:=xlLocationAsObject, Name:=Storage Charts ActiveChart.Parent.Name =
Sub omnama() ActiveSheet.Range(Cells($1, $A), Cells($39930, $Q))._ RemoveDuplicates Columns:=Array(1, 2, 6, 7, 8, 9), Header:=xlYes
Sub RowRangeMove() Sheets.Add().Name = CopySheet With Sheets(BigDataSet - Copy) .Range(A65000, .Range(A13000).End(xlUp)).Copy Destination:=Range(A1) With Sheets(BigDataSet
Public Sub MyFunction() Dim lowstring As String lowstring = hi Me.RichTextView.Find(lowstring, 0, 2) End
Public Sub textcolorchanged() Dim searchword As String = RichTextBox2.Text.ToString.Trim Dim index1 As Integer =
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s
Private Sub Command1_Click() Dim x As Integer For x = 1 To 100 List1.AddItem
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim allowedChars
Private Sub Command1_Click() Dim dom As New DOMDocument Dim http As New XMLHTTP Dim
Private Sub cmdLogin_Click() On Error GoTo ErrorHandler Dim RowNo As Long Dim Id As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.