A problem on VBA

ericvu23

New Member
Joined
Dec 19, 2010
Messages
17
Hi everyone,
I get a problem with my VBA codes,
As you can see:

Sub Flexible_average()
Dim n As Variant
Dim q As Variant
Dim m As Variant
Dim L As Variant

n = 7
rng1 = Range("A4").Value
rng2 = Range("A5").Value
Set Wtf = Application.WorksheetFunction

For i = 0 To 25
Range("H" & n + i) = WF.Average("B" & n + i & ":B" & n + i * rng1)
Next

End Sub

It is not working, can someone help me please??

Many thanks,
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Maybe

Code:
Sub Flexible_average()
Dim n As Long
Dim i As Long
Dim rng1
n = 7
rng1 = Range("A4").Value

For i = 0 To 25
    Range("H" & n + i) = WorksheetFunction.Average("B" & n + i & ":B" & n + i * rng1)
Next

End Sub
 
Upvote 0
Maybe something like this

Code:
Sub Flexible_average()
Dim n As Long
Dim i As Long
Dim rng1
n = 7
rng1 = Range("A4").Value

For i = 0 To 25
    Range("H" & n + i).Value = WorksheetFunction.Average(Range("B" & n + i & ":B" & n + i * rng1))
Next

End Sub
 
Upvote 0
Try this.
Code:
Sub Flexible_average()
Dim n As Variant
Dim q As Variant
Dim m As Variant
Dim L As Variant
Dim ans
    n = 7
    rng1 = Range("A4").Value
    rng2 = Range("A5").Value

    For i = 0 To 25
        
        ans = Application.Average(Range("B" & (n + i) & ":B" & (n + i * rng1)))
        If Not IsError(ans) Then
                Range("H" & n + i) = ans 
        End If
    Next
End Sub
 
Upvote 0
Try this.
Code:
Sub Flexible_average()
Dim n As Variant
Dim q As Variant
Dim m As Variant
Dim L As Variant
Dim ans
    n = 7
    rng1 = Range("A4").Value
    rng2 = Range("A5").Value
 
    For i = 0 To 25
 
        ans = Application.Average(Range("B" & (n + i) & ":B" & (n + i * rng1)))
        If Not IsError(ans) Then
                Range("H" & n + i) = ans 
        End If
    Next
End Sub

Thanks , i will see what it gives.

Cheers mate,
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,787
Members
449,188
Latest member
Hoffk036

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