LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default for loop with If then question

This code will loop through all your worksheets. I assume the data you are
trying to find is in Col. A. With each worksheet it will unlock all cells
then lock the row that contains the value you specify. You will have to
change your password and data value in this code to fit your application.
Hope this helps! If so, let me know, click "YES" below.

Sub LockRows()

Dim wks As Worksheet
Dim LastRow As Long
Dim rw As Long

For Each wks In Worksheets
With wks
.Unprotect Password:="Your Password Here"
.Cells.Locked = False
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

For rw = 2 To LastRow
If .Cells(rw, "A").Value = "Your Data" Then
.Rows(rw).Locked = True
End If
Next rw
.Protect Password:="Your Password Here"
End With
Next wks

End Sub
--
Cheers,
Ryan


"Steve" wrote:

Morning all.
I'm looking to set up an automatic password sheet protection tool and there
are only specific elements that I need protected on the worksheets in my
workbooks.
As such, my goal is to look for a value, in a single column, and if the
value exists in one cell, protect that row. All other rows will remain
unprotected.

As I think about this, it seems to me that I'd need a for loop to iterate
through the rows of that one column, and then use an IF statement to look for
a value.

Part of my struggle is that not all worksheets start at the same start row.
Nor do all worksheets end at the same row. Therefore, I need a variable to
delineate my start and end points. I've already learned that LastUsedRow does
not work well enough to use for this.

E.g.
for i = firstusedrow to lastusedrow step 1
if .cell() < "" OR " " then
Activesheet.protect.........

Your helps are appreciated.




 
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
Loop Do Until question Barry McConnell Excel Programming 6 July 9th 08 03:13 PM
For Next Loop Question GregR Excel Programming 8 May 27th 06 03:56 PM
end with loop question Lee Hunter Excel Programming 2 November 3rd 05 08:14 PM
do until...loop question Marcotte A Excel Programming 0 June 14th 04 08:47 PM
another loop question Patti[_5_] Excel Programming 5 May 31st 04 07:43 AM


All times are GMT +1. The time now is 01:51 PM.

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"