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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,595
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,067
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
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

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
morbiuss,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,191,119
Messages
5,984,758
Members
439,909
Latest member
daigoku

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
Top