+ Reply to Thread
Results 1 to 4 of 4

Check cell contents then format as locked

  1. #1
    Katherine
    Guest

    Check cell contents then format as locked

    I need a snippet of code that will check each cell in column K for the value
    "Y" - if there's a Y in the cell, I want to format that entire row as locked
    and then move down to check the next cell etc

    Can anyone help me with the syntax please?

  2. #2
    Bob Phillips
    Guest

    Re: Check cell contents then format as locked

    Sub LockRow()
    Dim cLastRow As Long
    Dim i As Long

    cLastRow = Cells(Rows.Count, "K").End(xlUp).Row
    For i = 1 To cLastRow
    If Cells(i, "K").Value = "Y" Then
    Cells(i, "K").EntireRow.Locked = True
    End If
    Next i
    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Katherine" <[email protected]> wrote in message
    news:[email protected]...
    > I need a snippet of code that will check each cell in column K for the

    value
    > "Y" - if there's a Y in the cell, I want to format that entire row as

    locked
    > and then move down to check the next cell etc
    >
    > Can anyone help me with the syntax please?




  3. #3
    Katherine
    Guest

    Re: Check cell contents then format as locked

    Thanks Bob

    Just so I understand, what is the xlUp part doing?

    "Bob Phillips" wrote:

    > Sub LockRow()
    > Dim cLastRow As Long
    > Dim i As Long
    >
    > cLastRow = Cells(Rows.Count, "K").End(xlUp).Row
    > For i = 1 To cLastRow
    > If Cells(i, "K").Value = "Y" Then
    > Cells(i, "K").EntireRow.Locked = True
    > End If
    > Next i
    > End Sub
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Katherine" <[email protected]> wrote in message
    > news:[email protected]...
    > > I need a snippet of code that will check each cell in column K for the

    > value
    > > "Y" - if there's a Y in the cell, I want to format that entire row as

    > locked
    > > and then move down to check the next cell etc
    > >
    > > Can anyone help me with the syntax please?

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Check cell contents then format as locked

    Hi Katherine,

    To have someone asking what it means, music :-).

    The Cells(Rows.Count,"K") gets the last cell in column K. By then adding
    End(xlUp) it is telling the code to find the first non-empty cell in the up
    direction. This has the net effect of finding the last non-empty cell in the
    column, including if there are some blanks in-between the start cell and the
    true last cell.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Katherine" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks Bob
    >
    > Just so I understand, what is the xlUp part doing?
    >
    > "Bob Phillips" wrote:
    >
    > > Sub LockRow()
    > > Dim cLastRow As Long
    > > Dim i As Long
    > >
    > > cLastRow = Cells(Rows.Count, "K").End(xlUp).Row
    > > For i = 1 To cLastRow
    > > If Cells(i, "K").Value = "Y" Then
    > > Cells(i, "K").EntireRow.Locked = True
    > > End If
    > > Next i
    > > End Sub
    > >
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Katherine" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I need a snippet of code that will check each cell in column K for the

    > > value
    > > > "Y" - if there's a Y in the cell, I want to format that entire row as

    > > locked
    > > > and then move down to check the next cell etc
    > > >
    > > > Can anyone help me with the syntax please?

    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1