|
-
Mar 26th, 2007, 06:20 AM
#1
Thread Starter
New Member
Cycle to block cells
Hi,
i have a problem, i want to make a loop to a column in excel, and when a cell is empty e want to block it, i made the code and what appens is when in the cycle is found a value different from empty, from there to front the program don't do anything. example if the first three cells are empty, the 4rd is with a value and the 5th is empty again, the program block the first three and then from there to the end of the cycle don't do anything.
Here is the code that i'm using:
protection = Sheets("SEM-BPS 1").ProtectContents
If protection = True Then
ThisWorkbook.Sheets("SEM-BPS 1").Unprotect ("SAP")
End If
ThisWorkbook.Worksheets("SEM-BPS 1").Activate
For Each c In ThisWorkbook.Worksheets("SEM-BPS 1").Range("A7", Range("A7").End(xlToRight)).Cells
If c.Value = "Planeado 2007" Then
For Each j In ThisWorkbook.Worksheets("SEM-BPS 1").Range(c.Address, Range(c.Address).End(xlDown)).Cells
If j.Value = Empty Then
Worksheets("SEM-BPS 1").Range(j.Address).Locked = True
End If
Next j
End If
Next c
If protection = True Then
ThisWorkbook.Sheets("SEM-BPS 1").EnableOutlining = True
ThisWorkbook.Sheets("SEM-BPS 1").Protect Password:="SAP", _
contents:=True, _
userInterfaceOnly:=True, _
DrawingObjects:=True
End If
-
Mar 26th, 2007, 05:31 PM
#2
Re: Cycle to block cells
Hi
You can only use xldown or xlright when you have continuous data...
for example if this is the case with Column A(see below) and if you use End(xlDown) from A1 then your last cell will always be A5 because cell A6 is blank.
A1 = some value
A2 = Blank
A3 = Blank
A4 = Blank
A5 = some value
A6 = Blank
A7 = some value
The best way to check this is enter some values in an excel sheet in the above format and then select Cell A1. Press Shift+End and then press the Down arrow key. you will notice that it selects cells only from A1:A5. Any cell after A5 will be ignored. That is the reason why the other cells are not considered in the loop...
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 27th, 2007, 06:45 AM
#3
Hyperactive Member
Re: Cycle to block cells
from the help screen...
SpecialCells Method
See AlsoApplies ToExampleSpecificsReturns a Range object that represents all the cells that match the specified type and value. Range object.
expression.SpecialCells(Type, Value)
expression Required. An expression that returns one of the objects in the Applies To list.
Type Required XlCellType. The cells to include.
XlCellType can be one of these XlCellType constants.
xlCellTypeAllFormatConditions. Cells of any format
xlCellTypeAllValidation. Cells having validation criteria
xlCellTypeBlanks. Empty cells
xlCellTypeComments. Cells containing notes
xlCellTypeConstants. Cells containing constants
xlCellTypeFormulas. Cells containing formulas
xlCellTypeLastCell. The last cell in the used range
xlCellTypeSameFormatConditions. Cells having the same format
xlCellTypeSameValidation. Cells having the same validation criteria
xlCellTypeVisible. All visible cells
Value Optional Variant. If Type is either xlCellTypeConstants or xlCellTypeFormulas, this argument is used to determine which types of cells to include in the result. These values can be added together to return more than one type. The default is to select all constants or formulas, no matter what the type. Can be one of the following XlSpecialCellsValue constants:
XlSpecialCellsValue can be one of these XlSpecialCellsValue constants.
xlErrors
xlLogical
xlNumbers
xlTextValues
Example
This example selects the last cell in the used range of Sheet1.
Worksheets("Sheet1").Activate
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Activate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|