Looping through to set values of range

Ligiea

New Member
Joined
Aug 15, 2005
Messages
9
I'm trying to automate a 60 step loop using the CycleThrough command button I made.

For i from 1 to 60 I want to:
... set cell J5 = i
... set value of cell at row # i of range M2:M61 to the value of cell K7

That's it. Each time J5 get's changed ten or so variables get set via in-cell INDEX-MATCH formulas and a few thousand of other cells get recomputed and spit out one grand result into K7, but i need to run 60 different cases. This is my first true written-from-scratch VBA (instead of cleaned up Macro Recorder) and I'm stumbling. I've used these forums to get this far but I can't tell where I'm going wrong. Thanks for reading/helping!

I had been using more comprehensive range callouts, Worksheets("StructAnalysis").Range

-------------------------

Private Sub CycleThrough_Click()
Dim i As Integer
Dim slope As Range
Set slope = Application.Range("M2:M61")
For i = 1 To 60
Application.Range(“J5”).Value = i
Application.Wait (Now + TimeValue("0:00:03"))
Application.Range(slope).Cells(i, 1).Value = Application.Range(“K7”).Value
Next i
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I banged my head against this for a couple of hours before ultimately solving this, by copy-pasting the code into a different module. Before that any time I tried to set a Range variable I'd get 1004 errors.
 
Upvote 0
I'm trying to automate a 60 step loop using the CycleThrough command button I made.

For i from 1 to 60 I want to:
... set cell J5 = i
... set value of cell at row # i of range M2:M61 to the value of cell K7

That's it. Each time J5 get's changed ten or so variables get set via in-cell INDEX-MATCH formulas and a few thousand of other cells get recomputed and spit out one grand result into K7, but i need to run 60 different cases. This is my first true written-from-scratch VBA (instead of cleaned up Macro Recorder) and I'm stumbling. I've used these forums to get this far but I can't tell where I'm going wrong. Thanks for reading/helping!

I had been using more comprehensive range callouts, Worksheets("StructAnalysis").Range

-------------------------
Maybe this:

Code:
Private Sub CycleThrough_Click()
Dim i As Long
For i = 1 To 60
Range("J5").Value = i
Application.Wait (NOW + TimeValue("0:00:03"))
Cells(i + 1, "M").Value = Range("K7").Value
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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