for loop

ttropics

New Member
Joined
Mar 3, 2018
Messages
7
can i make it so that you have to click a button to do a single step of my for loop
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
developer tab/insert/button(form control)

draw the button onto the spreadsheet where you want it, it will then ask you which macro you want it to run, select one and press ok.
 
Upvote 0
Yes, but wont this run the entire loop? I want the button to run 1 part of the loop, then the second click to run the next part of the loop.
 
Upvote 0
Yes it will run the entire macro,

without seeing the code its hard to say.

you could put something like

msgbox "Loop complete" at the place where you want it to stop

then when you press OK it will continue
 
Upvote 0
Private Sub CommandButton1_Click()


Columns("B:C").ColumnWidth = 22


range("a1").Value = "Number"
range("b1").Value = "Square of the Number"
range("c1").Value = "Square root of the Number"


range("a2:c2").Value = 1


Dim x As Integer


For x = 1 To 17
Cells(x, 1).Interior.Color = RGB(178, 178, 178)
Next x


For x = 3 To 17
Cells(x, 1).Value = (x - 2) + 1
Next x


For x = 2 To 17
Cells(x, 2).Value = ((x - 2) + 1) ^ 2
Next x


For x = 2 To 17
Cells(x, 3).Value = ((x - 2) + 1) ^ (1 / 2)
Next x




End Sub

This is my code and i need the button click to preform just one pert of the loop
 
Upvote 0
You would have to put a test in there such as:

Code:
Columns("B:C").ColumnWidth = 22

Range("A1").Value = "Number"
Range("B1").Value = "Square of the Number"
Range("C1").Value = "Square root of the Number"

For i = 2 To 17
    If Cells(i, 1).Interior.Color <> RGB(178, 178, 178) Then
        Cells(i, 1).Interior.Color = RGB(178, 178, 178)
        Cells(i, 1).Value = i - 1
        Cells(i, 2).Value = (i - 1) ^ 2
        Cells(i, 3).Value = (i - 1) ^ 0.5
        Exit For
    End If
Next
 
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