Hi all,
hope all is well.
Im trying to:
1. Protect a sheet using VBA. (I got this to work)
2. Use a range created using VBA as "Range Unlocked by password when sheet is protected" (I'm not sure if this will work, maybe someone can provide comments)
3. Use VBA to create a range of non contiguous cells based on condition NON-BLANK (this is where Im stuck at the moment).
The problem (item 3 above) is that the loop executes but:
a. Im never able to see if the cells required have actually been added to the range.
b. I cannot select the range to view it
Could somebody have a look and provide some ideas as to what I could be doing wrong? Below Im pasting the code and a link to the table below
Thanks in advance for your assistance
http://s8.postimg.org/kpb1vwc1h/Picture_of_table.png
hope all is well.
Im trying to:
1. Protect a sheet using VBA. (I got this to work)
2. Use a range created using VBA as "Range Unlocked by password when sheet is protected" (I'm not sure if this will work, maybe someone can provide comments)
3. Use VBA to create a range of non contiguous cells based on condition NON-BLANK (this is where Im stuck at the moment).
The problem (item 3 above) is that the loop executes but:
a. Im never able to see if the cells required have actually been added to the range.
b. I cannot select the range to view it
Could somebody have a look and provide some ideas as to what I could be doing wrong? Below Im pasting the code and a link to the table below
Thanks in advance for your assistance
Code:
Sub Create_WorkRange()
Dim WorkRange As Range
Dim Lrow As Long
Dim i As Long
'Find the last used row:
Lrow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets("Sales and cost of sales").Select
'Loops checking for NON_BLANKS in column F:
For i = 3 To Lrow
If Range("F" & i) <> "" Then
If WorkRange Is Nothing Then
Set WorkRange = Range("F" & i & ":" & "O" & i)
Else
Set WorkRange = Union(WorkRange, Range("F" & i & ":" & "O" & i))
End If
End If
Next i
'With the following line I try to select the created range so I can view it
'but it gives me error:
'Run-time error '1004:
'Methor 'Range' of object'_Global' failed
'hence I commented it
'Range("WorkRange").Select
'The following line actually writes the range but it refers to "WorkRange"
'and as result I dont know which cells it is actually adding to the range
ActiveSheet.Names.Add Name:="WorkRangePermission", RefersTo:= _
"WorkRange"
End Sub
http://s8.postimg.org/kpb1vwc1h/Picture_of_table.png
Last edited: