Repete this code for every row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esperanto234
    New Member
    • Sep 2009
    • 14

    Repete this code for every row

    Hi, I have this code to lock some cells if date has passed:

    Code:
    If [MARCADORES!E3] <= Date Then
    ActiveSheet.Unprotect ("mundial")
    ActiveSheet.Range("MARCADORES!I3:T3").Locked = True
    ActiveSheet.Protect ("mundial")
    Else
    ActiveSheet.Unprotect ("mundial")
    ActiveSheet.Range("MARCADORES!I3:T3").Locked = False
    ActiveSheet.Protect ("mundial")
    End If
    How can i do to repeat this in every row??

    For :
    [MARCADORES!E4] - ActiveSheet.Ran ge("MARCADORES! I4:T4")
    [MARCADORES!E5] - ActiveSheet.Ran ge("MARCADORES! I5:T5")
    and so on...........
  • dsatino
    Contributor
    • May 2010
    • 393

    #2
    All my VBA is in Access so I'm just assuming that a lot of the functionality is the same....

    You need to set up a variable and Loop statement

    Public Sub Test()
    dim x as integer
    dim strVar as string

    x=1

    Do
    strVar="[MARCADORES!E" & x & "]"

    If strVar <= Date Then
    ActiveSheet.Unp rotect ("mundial")
    ActiveSheet.Ran ge("MARCADORES! I3:T3").Locked = True
    ActiveSheet.Pro tect ("mundial")
    Else
    ActiveSheet.Unp rotect ("mundial")
    ActiveSheet.Ran ge("MARCADORES! I3:T3").Locked = False
    ActiveSheet.Pro tect ("mundial")
    End If

    x=x+1
    Loop
    End Sub

    You'll have to modify this to Excel specifically, but hopefully this gives you the general idea. Also the Do/Loop as it is above will pretty much run forever so you'll to change it to a Do Until/Loop in which you've set the Until to max number.

    Comment

    Working...