Repeat code to "n" cells

Hi all

My code reads one cell and through the options it locks or not others cells. 
Im trying to extend my programming to all subsequent cells. How can I do it? 
Like using "for" instruction?!?! Does anybody help me?

Private Sub Worksheet_Change(ByVal Target As Range)
If [E9]= "A" Then
ActiveSheet.Unprotect ("")
ActiveSheet.Range("G9:K9").Locked = True
ActiveSheet.Range("F9").Locked = False
[G9:K9].Interior.ColorIndex = 15
[F9].Interior.ColorIndex = 0
ActiveSheet.Protect ("")
ElseIf Target.Cells.Text = "B" Then
ActiveSheet.Unprotect ("")
ActiveSheet.Range("G9:K9").Locked = False
ActiveSheet.Range("F9").Locked = True
[G9:K9].Interior.ColorIndex = 0
[F9].Interior.ColorIndex = 15
ActiveSheet.Protect ("")
Else
ActiveSheet.Unprotect ("")
ActiveSheet.Range("F9:K9").Locked = True
[F9:K9].Interior.ColorIndex = 15
ActiveSheet.Protect ("")
End If

End Sub


Thanks in advance


Kelson
kelsonbatista@yahoo.co.uk
kelsjc@hotmail.com


0
Kelson (1)
10/10/2007 6:47:05 PM
excel.newusers 15348 articles. 2 followers. Follow

1 Replies
585 Views

Similar Articles

[PageSpeed] 13

Please don't multipost.

You have responses at several of your other threads.

Kelson wrote:
> 
> Hi all
> 
> My code reads one cell and through the options it locks or not others cells.
> Im trying to extend my programming to all subsequent cells. How can I do it?
> Like using "for" instruction?!?! Does anybody help me?
> 
> Private Sub Worksheet_Change(ByVal Target As Range)
> If [E9]= "A" Then
> ActiveSheet.Unprotect ("")
> ActiveSheet.Range("G9:K9").Locked = True
> ActiveSheet.Range("F9").Locked = False
> [G9:K9].Interior.ColorIndex = 15
> [F9].Interior.ColorIndex = 0
> ActiveSheet.Protect ("")
> ElseIf Target.Cells.Text = "B" Then
> ActiveSheet.Unprotect ("")
> ActiveSheet.Range("G9:K9").Locked = False
> ActiveSheet.Range("F9").Locked = True
> [G9:K9].Interior.ColorIndex = 0
> [F9].Interior.ColorIndex = 15
> ActiveSheet.Protect ("")
> Else
> ActiveSheet.Unprotect ("")
> ActiveSheet.Range("F9:K9").Locked = True
> [F9:K9].Interior.ColorIndex = 15
> ActiveSheet.Protect ("")
> End If
> 
> End Sub
> 
> Thanks in advance
> 
> Kelson
> kelsonbatista@yahoo.co.uk
> kelsjc@hotmail.com

-- 

Dave Peterson
0
petersod (12005)
10/10/2007 10:19:21 PM
Reply:

Similar Artilces:

can I find merged cells?
I'm trying to sort and get the message "merged cells must be the same size". How can I 'find' the merged cells? David, here is a macro by Dave Peterson that will do it Sub Found_Merged_Cells() 'macro looks for merged cells 'By Dave Peterson Dim myCell As Range Dim resp As Long For Each myCell In ActiveSheet.UsedRange.Cells If myCell.MergeCells Then If myCell.Address = myCell.MergeArea(1).Address Then resp = MsgBox(prompt:="found: " _ & myCell.MergeArea.Addre...

Write formula for simple copy and paste to another cell
I have a worksheet that contains hundreds of columns. Each group of three are related to each other (Cols A-C, D-F, etc...). I have this formula that works well for columns A-C =IF(NOT(ISBLANK('Page 5 Counts'!B2)),VLOOKUP('Page 5 Counts'!B2,'Color Key'!$A$1:$B$87,2,FALSE),IF(AND(COLUMN()=COLUMN($B$1),ROW()=1),IF($A$2=$A$1,"",1),IF(AND(COLUMN()=COLUMN($C$1),ROW()=1),$B$1,IF(AND(COLUMN()=COLUMN($B$2),ROW()=2),IF($A$2=$A$1,2,1),IF(AND(COLUMN()=COLUMN($C$2),ROW()=2),IF($A$2=$A$3,"",IF($A$2=$A$1,$B$2,1)),IF(AND(COLUMN()=COLUMN($B$3),ROW()=3),IF($A...

Copying cell contents to a list
First of all - apologies if this is in the wrong group. I wasn't sure if it should be newusers (which I am) or programming (which I might need). I have inherited a lottery syndicate at work after the previous organiser retired. He kept an Excel 97 spreadsheet with 8 columns - A (Date), B to G (Winning numbers) and H (Bonus number). This list has now grown to about 800 rows as each draw's numbers are added to the bottom of the list (I will be removing about 600). I have adapted the spreadsheet to automatically check our numbers against the winning numbers (using HLOOKUP) after I have ...

Place X in cell if criteria met`
Is there a formula to do this? If cell B2 = pencils Put an "X" in cell B7 If cell B2 = pens Put an "X" in cell B8 If cell B2 = erasers Put an "X" in cell B9 Thanks in advance in cells B7 put =if(B2="pencils","x","") in Cell B8 put =if(B2="pens","x","") In cell B9 put =if(B2="erasers","x","") "jhicsupt" wrote: > Is there a formula to do this? > > If cell B2 = pencils > Put an "X" in cell B7 > > If cell B2 = pens ...

Send Email With Cell Conent as Part of the Subject
Hyperlink is able to send email with cell content in the Subject line. My Case =HYPERLINK("mailto:Collections_Admin?subject=Overdue Balance " & "_"& 'Sheet1'!G15,"Email To Collection Agency") Sheet1G15 has the data I want to show in the subject line. Is it possible to do this with Macros? I am using Lotus Notes for email. Thanks Igbert For lotus code see Sending mail from Lotus Notes (XL-Dennis) http://www.excelkb.com/?cNode=1X5M7A -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "igbe...

Label a button from a cell content
Hello, Using Excel 97, is their a way to aquire the label for a button from cell on a different worksheet? :confused: Thanks in advance, Sp -- spyrul ----------------------------------------------------------------------- spyrule's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2548 View this thread: http://www.excelforum.com/showthread.php?threadid=38935 ...

inserting texts in cell based on conditions
Hi, I would very much appreciate if someone could help me solving a problem, illustrated by the following example: Column A B C 1 1 "LB" 2 1 "DK" 3 4 1 1 "LB/DK" If there's a 1 in column A, the corresponding cell in column C should get the text "LB" inserted into it. If there's a 1 in column C, the corresponding cell in column C should get the text "DK" inserted into it. If both column A and B have ones in them, the corresponding cell should get the...

How do I Add and Subtract percentages in cells
Can anybody help I am trying to add and subtract percentages from cells deducting tax from wages etc. How do i go about it.As i am new to excel Thanks in advance. Ron Ronnie Check out this on-line tutorial for Excel. http://www.usd.edu/trio/tut/excel/index.html Specifically the "Basic Math" section. http://www.usd.edu/trio/tut/excel/13.html Gord Dibben Excel MVP On Sun, 1 Aug 2004 23:06:56 +0100, "Ronnie" <ronnie@broraweb.co.uk> wrote: >Can anybody help I am trying to add and subtract percentages from cells >deducting tax from wages etc. >How do i ...

I want to format a cell based on an adjacent cells value
I would like a cell automatically formatted in the same way a conditional format works - but the format to be based on the value of an adjacent cell. Any ideas as I cant work out how or if I can achieve this Cumbo, Use Conditional Formatting, but change cell valve is to formula is and use something like this, will change the cell if A1=25 =$A$1=25, so if you select B5 and put this in conditional formatting cell B5 will change when A1 = 25 -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on an...

calculation of cells
Periodically I open a work book and the calculation option has been changed to manual and I cannot figure out why. It seems that it would have to be done by a user and most of my spreadsheets are only used by me. Any ideas out there Mark, Calculation, auto or manual, is set by the first workbook that's opened. It is that way for any other workbooks opened in that instance of excel. Look for a workbook you might have opened first that's been set to Manual and saved that way. Go figure. -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------...

Counting cells based on color
I am looking for a "counting" formula that will count cells in a rang based on their color, so that if I color a series of dates (to sho 'vacation) the number of cells (days) will be counted...to keep trac of vacation...thanks -- Message posted from http://www.ExcelForum.com There's no built-in functionality for that - it requires a UDF (user-defined function). You'll find several examples in the google archives: http://www.google.com/advanced_group_search? as_ugroup=*excel*&lr=&num=100&hl=en MVP Chip Pearson also has some code: http://www.cpearson.com...

Multiple IF statements in one cell
Excel 2003 on XP. I have a project control listing that has, in part of it, nine columns that will hold the dates that certain stages are met, i.e. a date will be entered as each stage is met and the following stages will be empty, until Stage 9 - Project Complete/Signed Off. Stages 1-9 each have a unique Stage Name/defintion. I would like a following cell in the row to automatically show the Stage Name for the latest date in the corresponding stage cell for that project. I have a nested IF statement that works but as the project list is to get very large I would like a neater way of doin...

Automating transfer of data in cells
I have a time management spreadsheet with data stored against work type and date. I need to transfer this data into a similar but more comprehensive spreadsheet and wonder whether it is possible to automate this task by using the work types and dates in a macro (I have almost 10 months of data to transfer), along the lines of check date, check worktype, where argument is true enter data from cell. I think I need to use visual basic, but I can't find out how in the help screens. Any advice is much appreciated. This is not difficult providing you keep your data in simple tables...

Cell formats, and time difference
Hi, some simple questions which I hope someone can help with... I am using excel on a computer with "danish locale". This means that numbers are displayed default like 1234,56. How do I change this to a format using a decimal point (instead of a comma)? How do I find the difference between to times? I have cells which just have times (not dates), and I want to find the difference between two times in hours. For example cells with 08:00 and 09:30 should give a difference of 1.5 Excel help gives an example like =TEXT(B2-A2,"h"), but this gives an error... Thanks, Pet...

Skip blank cells in diagrams
How do I exclude blank cells in diagrams. If I have an area of data and among these data some is blank. How do I get excel to not display these data as '0' but just to skip the cell. You can include the function NA() in that field and the zero value for the data won't be displayed. "hlp" <hlp@discussions.microsoft.com> wrote in message news:4FF83D9F-F13E-4815-BDDE-26F44F2E6BE1@microsoft.com... > How do I exclude blank cells in diagrams. If I have an area of data and among > these data some is blank. How do I get excel to not display these data as '0...

Save spreadsheet using cell values as filename
I am trying to use a command button to save a spreadsheet using cell values as the file name from the tab Master. For example I want to use cells B2 (Tony.Dungate) and F2 (2010.March) to create a file name of Tony.Dungate.2010.March.xls. Essentialy I would need something like : Master!B2&.&Master!G2&".xls" Can someone advise me on the correct code to do this. I have been trying to use the following without success: Const sRoot As String = "V:\Database Logs\" With ActiveWorkbook .SaveAs Filename:=sRoot & _ ....

returning vlookup values for blank cells
I have a spreadsheet that lists "soccer players" by name down the first colunm and "time in game" across the top and the position they play in array. I then use vlookup for another spreedsheet by "position" down the first column, time across the top and puts the players name into the positions. All this works fine. Since there are 5 more kids than positions, the orginal spreedsheet has blanks when the kids are out of the game. How do I use vlookup or other to extract the 5 sub'd out kids at the bottom of the 2nd spreadsheet? It only returns the nam...

minimum for casual cells but >0
I have big table with vendors, and I have to find the lowest price for each item, but prices are like: A B C D E F G H I etc. Item x 128 175 0 215 the problem is there are also columns with quantities which shouldn't be included I don't want to include columns e.g. B, D, F etc. AND find minimum price but >0. so I can't use: MIN(C1,E1,G1,I1...) because I'll get 0 as result. I'm looking for the simplest solution. Appreciate for any help. Ctrl/shift/ente...

Formatting hyperlinks in an Excel cell 02-16-10
Two of the columns in a spreadsheet (Excel 2003) that I use record email and web addresses. All of them appear as hyperlinks i.e. blue and underlined but some occasionally seem to lose their hyperlink properties. This means that when one hovers over them, the cursor stays as the usual Excel cross rather than changing to the hand/finger symbol. Also, clicking on the former does not launch the browser. Is there any way to ensure they are formatted, and work, as hyperlinks please? TIA V ...

The cursor in Excel select groups of cells and I can't get out.
I have found that my cursor seems to lock up for some unknown reason occasionally and when I try to escape I can't get out. The program just selects the adjacent cells wherever I move my mouse. It is maddening since I must shut down Excel to get out. Does anyone know why this is happening? http://www.mvps.org/dmcritchie/excel/ghosting.txt Regards, Peo Sjoblom "Jenn" wrote: > I have found that my cursor seems to lock up for some unknown reason > occasionally and when I try to escape I can't get out. The program just > selects the adjacent cells wherever ...

Combined date time cell to separate date & time components #3
From file dump have combined date time cells eg 14/04/03 14:20 (value 37725.59722). Want to perform time analysis so need to split to 2 separate cells; eg. "14/04/2003" (value 37725) & "14:20" (value 0.59722). Is there a fnc to do this? (Currently convert cell to value, then fncs trunc & cell less int(cell) then refmt to date dd/mm/yy & time hh:mm respectively) Please look for the previous answers you've gotten, including at least 2 to your identical post yesterday. In article <F0A5B5BA-2E80-4875-A042-D3514FD4E228@microsoft.com>, "Ma...

This code doesn't work, why?
Create a new MCF project (test_odbc). Using the wizard, add a class to conect to a database in SQL server (CMyDB). The code looks like this: void Ctest_odbcApp::fun1(CRecordset *pRS) { CString csValue; pRS.GetFieldValue(0,csValue); // <- Generates a CDBException. Why? } BOOL Ctest_odbcApp::InitInstance() { CMyDB cDB; CString csValue; try { cDB.Open(); cDB.MoveFirst(); cDB.GetFieldValue(0,csValue);// <- This works fine fun1(&cDB); cDB.Close(); } catch(CDBException *pDBE) { pDBE->ReportError()...

What is the max length of a single piece of code?
I am trying to make this rather long piece of code work, but when I paste it, the VBA window makes it Red 'error' Text. Is their a maxiumum length that VBA will allow? stAppName = "C:\Program Files\Internet Explorer\iexplore.exe http://maps.google.co.uk/maps?f=q&hl=en&q=" & "from: " & Me.RunWaypoint_1 + ", London" & (" to: " + Me.RunWaypoint_2 + ", London") & (" to: " + Me.RunWaypoint_3 + ", London") & (" to: " + Me.RunWaypoint_4 + ", London") & (" to: ...

Is there a way to put html code in title attribute in xsl? thanks!
I need put some html code into title attribute of A tag, so that user could see html when they move mouse over the link, I think this isn't a standard use, but it does work. The problem is how can I prevent the xsl transfer the html when it does the transformation. I would like something like <A title="<b>test</b>"> but I end up with <A title="&lt;b&gt;test&lt;/b&gt;"> Any idea? Thanks! david wrote: > I need put some html code into title attribute of A tag, so that user could > see html when they move mouse over the lin...

Extract numbers from cells
I have 2 columns of numbers in a sheet called "Fill up Records". I wish to copy the data in the 2nd to last cell before a blank in one column ( L) and the last number before a blank in the other column (C) and divide the first by the second and put the answer on a different sheet. The blank cells only occur after the first blank cell. What formula would I use in the second sheet to do this? Assume data in sheet: Fill up Records in col L is within rows 1 - 100 (say) in col C is within rows 1 - 200 (say) Then in the other sheet, Try this expression, array-entered (press CTRL+SHIF...