Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in message
...
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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba to check cell contents Steve Excel Discussion (Misc queries) 2 July 29th 09 04:58 PM
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM
check for repetition of cell contents David Excel Worksheet Functions 1 September 14th 06 09:31 AM
How can user move in locked worksheet but not copy cell contents? PAT Excel Worksheet Functions 0 April 25th 06 08:40 PM
Fussy check of cell contents access_mk Excel Discussion (Misc queries) 1 April 19th 06 01:28 PM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"