simple code needed

morbiuss

New Member
Joined
Aug 14, 2014
Messages
6
Hello

I have this code

Sub endturn()​
If Sheets("condition").Range("k2").Value = True Then​
Sheets("condition").Range("m2").Value = Sheets("condition").Range("m2").Value - 1​
End If

If Sheets("condition").Range("k3").Value = True Then
Sheets("condition").Range("m3").Value = Sheets("condition").Range("m3").Value - 1
End If

End Sub​

that work fine
but i'd like to have the same thing to every line up to 100 without copying it 100 times
is there a way?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try
Code:
Sub MM1()
dim r as long
For r = 2 To 100
If Sheets("condition").Range("k" & r).Value = True Then
Sheets("condition").Range("m" & r).Value = Sheets("condition").Range("m" & r).Value - 1
End If
Next r
end sub
 
Upvote 0
With Sheets("condition")
For i = 2 to 101
If .Cells(i,"K").Value = True Then
.Cells(i,"M").Value = .Cells(i,"M").Value - 1
End If
Next i
End With
 
Upvote 0
morbiuss,

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub endturnV2()
' hiker95, 09/04/2014, ME803444
Dim r As Long
Application.ScreenUpdating = False
With Sheets("condition")
  For r = 2 To 100
    If .Range("k" & r).Value = True Then
      .Range("m" & r).Value = .Range("m" & r).Value - 1
    End If
  Next r
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the endturnV2 macro.
 
Upvote 0
morbiuss,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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