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
[TABLE="width: 1061"]
<colgroup><col><col><col span="13"></colgroup><tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[TD]N[/TD]
[TD]O[/TD]
[/TR]
[TR]
[TD]S/L[/TD]
[TD]Prime[/TD]
[TD]UK[/TD]
[TD]Desc.[/TD]
[TD]Division[/TD]
[TD]Category[/TD]
[TD]W1[/TD]
[TD]W2[/TD]
[TD]W3[/TD]
[TD]W4[/TD]
[TD]W5[/TD]
[TD]W6[/TD]
[TD]W7[/TD]
[TD]W8[/TD]
[TD]DMD[/TD]
[/TR]
[TR]
[TD]DDD[/TD]
[TD]TTTT[/TD]
[TD]E2[/TD]
[TD]rrrr[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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