Run Time Error 91

Brett.Ferguson

New Member
Joined
Jun 13, 2011
Messages
4
Hi, I am new to excel and am getting the error message Object variable or With block variable not set, I do not know what this means. If someone could explain why this may be occurring that would be great. Thanks

Brett
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Welcome to the board..

It could be any one of several problems...

Can you post the relevant code, and tell us which line is highlighted when you click Debug..
 
Upvote 0
or i = 0 To 23 'hours
For j = 0 To 59 'minutes
If rec1secdata(0, i, j, 0).blnValid = True Then 'Valid minute
With rec1minData(i, j)
For col_cnt = 12 To 13 'on each 1 second data column
col_cnt1 = 88
For k = 0 To 59 'seconds

'get 60 second average for both wind speed readings

'60 second sum for wind speed 1
avg1 = _
avg1 + rec1secdata(0, i, j, k).sngCol(12)

'60 second average for wind speed 1
avg1 = avg1 / 60

'60 second sum for wind speed 2
avg2 = _
avg2 + rec1secdata(0, i, j, k).sngCol(13)

'60 second average for wind speed 1
avg2 = avg2 / 60

'Get the value for the numerator of the correlation coefficient equation
SumNumerator = SumNumerator + _
((rec1secdata(0, i, j, k).sngCol(12) - avg1) * _
(rec1secdata(0, i, j, k).sngCol(13) - avg2))

'Get the value for the first half of the denominator of the correlation coefficient equation
SumDenominator1 = SumDenominator1 + _
(rec1secdata(0, i, j, k).sngCol(12) - avg1) ^ 2

'Get the value for the second half of the denominator of the correlation coefficient equation
SumDenominator2 = SumDenominator2 + _
(rec1secdata(0, i, j, k).sngCol(13) - avg2) ^ 2

'Getiing the correlation coefficient for each 60 second data period
Correl = SumNumerator / Sqr((SumDenominator1 ^ 2) * _
(SumDenominator2 ^ 2))

Next
Next 'Col_cnt
End With
End If
Next 'Min
Next 'hour


The avg1 line is highlighted
 
Upvote 0
It looks like it's expecting rec1secdata to be returing a range, but it's not..

I think we need to see the codes for
rec1secdata and rec1minData

And possibly an explaination of what this code is meant to do...
 
Upvote 0
Alright, I will try and explain what my code is supposed to do. My code is being added to a massive excel spreadsheet that takes in thousands of lines of data and I need my section to generate a correlation coefficient but I was told I can not use the standard excel formula as we take in 1 second data of wind speed and I need to calculate a correlation coefficient for each minute of data.

Here is the code again..

Code:
    Dim avg1 As Range
    Dim avg2 As Range
    Dim SumNumerator As Range
    Dim SumDenominator1 As Range
    Dim SumDenominator2 As Range
    Dim Correl As Double
    
    For i = 0 To 23             'hours
        For j = 0 To 59         'minutes
            If rec1secdata(0, i, j, 0).blnValid = True Then    'Valid minute
                With rec1minData(i, j)
                    For col_cnt = 12 To 13 'on each 1 second data column
                        col_cnt1 = 88
                            For k = 0 To 59     'seconds
                            
                            'get 60 second average for both wind speed readings
                                                    
                            '60 second sum for wind speed 1
                            avg1 = _
                            avg1 + rec1secdata(0, i, j, k).sngCol(12)
                            
                            '60 second average for wind speed 1
                            avg1 = avg1 / 60
                            
                            '60 second sum for wind speed 2
                            avg2 = _
                            avg2 + rec1secdata(0, i, j, k).sngCol(13)
                            
                            '60 second average for wind speed 1
                            avg2 = avg2 / 60
                            
                            'Get the value for the numerator of the correlation coefficient equation
                            SumNumerator = SumNumerator + _
                            ((rec1secdata(0, i, j, k).sngCol(12) - avg1) * _
                            (rec1secdata(0, i, j, k).sngCol(13) - avg2))
                        
                            'Get the value for the first half of the denominator of the correlation coefficient equation
                            SumDenominator1 = SumDenominator1 + _
                            (rec1secdata(0, i, j, k).sngCol(12) - avg1) ^ 2
                            
                            'Get the value for the second half of the denominator of the correlation coefficient equation
                            SumDenominator2 = SumDenominator2 + _
                            (rec1secdata(0, i, j, k).sngCol(13) - avg2) ^ 2
                            
                            'Getiing the correlation coefficient for each 60 second data period
                            Correl = SumNumerator / Sqr((SumDenominator1 ^ 2) * _
                            (SumDenominator2 ^ 2))
                                                     
                        Next
                    Next    'Col_cnt
                End With
            End If
        Next    'Min
    Next    'hour
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

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