referencing cells from vba

khatri milan

New Member
Joined
Nov 6, 2019
Messages
17
as shown in code below, i have defined two varible m and n and tried to use these variable for addressing a cell like range("cn") in place of range("c4") during first loop, but it shown run time error 1004 , cant i address a range in this way?

Sub test()
Dim diameter As Long
Dim maxcap As Long
Dim m As Integer
Dim n As Integer
For m = 74 To 76
For n = 4 To 22
maxcap = Worksheets("9_Sling Data").Range("cn").Value
If maxcap >= Range("im").Value Then
Range("hm").Value = maxcap
Range("gm").Value = Worksheets("9_Sling Data").Range("an").Value
Range("jm").Value = Round(Range("im").Value / Range("hm").Value, 2)
Exit For
Else
End If
Next n
Next m
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Range("cn") should be Range("c" & n)
Range("im") should be Range("i" & m)
etc
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,761
Messages
6,174,344
Members
452,556
Latest member
Chrisolowolafe

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