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
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,571
Office Version
365
Platform
Windows
Range("cn") should be Range("c" & n)
Range("im") should be Range("i" & m)
etc
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,571
Office Version
365
Platform
Windows
You're welcome, glad to help, & thanks for the feedback.:)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,959
Messages
5,508,409
Members
408,682
Latest member
alifarhat

This Week's Hot Topics

Top