Range Error in VBA Code

srlakra

New Member
Joined
Mar 24, 2015
Messages
23
Rich (BB code):
Sub Deploy()


Dim i, x, y, z As Long
Dim R1, R12 As Range


x = Cells(Rows.Count, "A").End(xlUp).Row

For i = 9 To x

R1 = Range("G" & i & ":J" & i)
R12 = Range("K" & i & ":M" & i)

y = Application.WorksheetFunction.Average(R1)
z = Application.WorksheetFunction.Average(R12)

Cells(i, "O") = Application.WorksheetFunction.Max(y, z)

Next i

End Sub

Excel is
ABCDEFGHIJKLMNO
S/LPrimeUKDesc.DivisionCategoryW1W2W3W4W5W6W7W8DMD
DDDTTTTE2rrrr0001012310

<colgroup><col><col><col span="13"></colgroup><tbody>
</tbody>


Getting error in bold line Plz help
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Re: Range Error in VBA Code Please help

Try changing your Dim Statements

Code:
Dim i, x, y, z As Long
Dim R1, R12 As Range

to

Code:
Dim i as long, x as long, y as long, z As Long
Dim R1 as variant, R12 As variant
 
Upvote 0
Re: Range Error in VBA Code Please help

Code:
Dim R1 as Range
Set R1 = Range("G" & i & ":J" & i)
Set R12 = Range("K" & i & ":M" & i)
HTH. Dave
 
Upvote 0
Re: Range Error in VBA Code Please help

You are welcome. Thanks for posting your reply. Dave
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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