Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Improve code that checks a range of names - currently using Activate

I have a spreadsheet with some hidden helper columns. One of these columns
is titled "Delete Row Allowed" and contains TRUE or a blank. True means
that the yes, the row can be deleted. In the spreadsheet, I've defined a
name, "boolDeleteItemAllowed" which refers to "=MySheet!$G1". Thus, the
name always tells whether the currently selected row can be deleted.

In my code I've got the following function, which checks whether row
deletion is allowed. It checks all the rows in the current selection. It
activates one cell in each row to do this. I haven't used Activate in code
for some time, but I'm not sure how to get the relative reference in each
row without it.

Function DeleteRowAllowed() As Boolean
Dim cell As Range
Dim rngActiveCell As Range

DeleteRowAllowed = True
With Workbooks("MyBook.xls").ActiveSheet
'need to set this back at end
Set rngActiveCell = ActiveCell
'check one cell in each row
For Each cell In Selection.Columns(1).Cells
cell.Activate
If CBool(.Names("boolDeleteRowAllowed").RefersToRange .Value) = False
Then
DeleteRowAllowed = False
Exit Function
End If
Next cell
'set back to original ActiveCell
rngActiveCell.Activate
End With
End Function

I don't think it's a big deal in terms of efficiency. As soon as it hits a
blank row it exits and I'll add ScreenUpdating = False. But I am curious if
there's a way to do it without Activate and still keeping the defined names
in the worksheet.

Thanks in advance,

Doug


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Improve code that checks a range of names - currently using Activate

Hi Doug,

I am not certain that I have understood
your requirement, but, perhaps, try:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range

Set Rng = Selection.EntireRow.Columns("G:G")
DeleteRowAllowed3= _
Application.CountIf(Rng, "False") 0

End Function
'<<=========



---
Regards.
Norman


"Doug Glancy" wrote in message
...
I have a spreadsheet with some hidden helper columns. One of these columns
is titled "Delete Row Allowed" and contains TRUE or a blank. True means
that the yes, the row can be deleted. In the spreadsheet, I've defined a
name, "boolDeleteItemAllowed" which refers to "=MySheet!$G1". Thus, the
name always tells whether the currently selected row can be deleted.

In my code I've got the following function, which checks whether row
deletion is allowed. It checks all the rows in the current selection. It
activates one cell in each row to do this. I haven't used Activate in
code for some time, but I'm not sure how to get the relative reference in
each row without it.

Function DeleteRowAllowed() As Boolean
Dim cell As Range
Dim rngActiveCell As Range

DeleteRowAllowed = True
With Workbooks("MyBook.xls").ActiveSheet
'need to set this back at end
Set rngActiveCell = ActiveCell
'check one cell in each row
For Each cell In Selection.Columns(1).Cells
cell.Activate
If CBool(.Names("boolDeleteRowAllowed").RefersToRange .Value) =
False Then
DeleteRowAllowed = False
Exit Function
End If
Next cell
'set back to original ActiveCell
rngActiveCell.Activate
End With
End Function

I don't think it's a big deal in terms of efficiency. As soon as it hits
a blank row it exits and I'll add ScreenUpdating = False. But I am
curious if there's a way to do it without Activate and still keeping the
defined names in the worksheet.

Thanks in advance,

Doug


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Improve code that checks a range of names - currently using Activate

Norman,

Thanks, but that's not it. In each row, the cell value in column G could be
True or not. Some rows, basically detail rows in a bid, can be deleted,
others can not. If multiple rows are selected and any of the values is not
True then the function must return False.

I may be making it more complicated than necessary by referring to the
name - I could do something like what you've done. I am interested though
in keeping as much of the logic in the worksheet as possible, and so would
like to use the name.

Thanks,

Doug

"Norman Jones" wrote in message
...
Hi Doug,

I am not certain that I have understood
your requirement, but, perhaps, try:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range

Set Rng = Selection.EntireRow.Columns("G:G")
DeleteRowAllowed3= _
Application.CountIf(Rng, "False") 0

End Function
'<<=========



---
Regards.
Norman


"Doug Glancy" wrote in message
...
I have a spreadsheet with some hidden helper columns. One of these
columns is titled "Delete Row Allowed" and contains TRUE or a blank. True
means that the yes, the row can be deleted. In the spreadsheet, I've
defined a name, "boolDeleteItemAllowed" which refers to "=MySheet!$G1".
Thus, the name always tells whether the currently selected row can be
deleted.

In my code I've got the following function, which checks whether row
deletion is allowed. It checks all the rows in the current selection.
It activates one cell in each row to do this. I haven't used Activate in
code for some time, but I'm not sure how to get the relative reference in
each row without it.

Function DeleteRowAllowed() As Boolean
Dim cell As Range
Dim rngActiveCell As Range

DeleteRowAllowed = True
With Workbooks("MyBook.xls").ActiveSheet
'need to set this back at end
Set rngActiveCell = ActiveCell
'check one cell in each row
For Each cell In Selection.Columns(1).Cells
cell.Activate
If CBool(.Names("boolDeleteRowAllowed").RefersToRange .Value) =
False Then
DeleteRowAllowed = False
Exit Function
End If
Next cell
'set back to original ActiveCell
rngActiveCell.Activate
End With
End Function

I don't think it's a big deal in terms of efficiency. As soon as it hits
a blank row it exits and I'll add ScreenUpdating = False. But I am
curious if there's a way to do it without Activate and still keeping the
defined names in the worksheet.

Thanks in advance,

Doug




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Improve code that checks a range of names - currently using Activate

Hi Doug,

Since you define the right to delete a row
according to the value of the corresponding
column G cell, why not use this in your
function rather than a derived condition:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range
Dim rCell As Range
Dim aCell As Range

Set Rng = Selection

For Each rCell In Rng.Columns(1).Cells
Set aCell = Application.Intersect(rCell.EntireRow, _
Rng.Parent.Columns("G:G"))
If aCell.Value = "False" Then
DeleteRowAllowed = False
Exit Function
End If
Next rCell

End Function
'<<=========



---
Regards.
Norman
"Doug Glancy" wrote in message
...
Norman,

Thanks, but that's not it. In each row, the cell value in column G could
be True or not. Some rows, basically detail rows in a bid, can be
deleted, others can not. If multiple rows are selected and any of the
values is not True then the function must return False.

I may be making it more complicated than necessary by referring to the
name - I could do something like what you've done. I am interested though
in keeping as much of the logic in the worksheet as possible, and so would
like to use the name.

Thanks,

Doug

"Norman Jones" wrote in message
...
Hi Doug,

I am not certain that I have understood
your requirement, but, perhaps, try:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range

Set Rng = Selection.EntireRow.Columns("G:G")
DeleteRowAllowed3= _
Application.CountIf(Rng, "False") 0

End Function
'<<=========



---
Regards.
Norman


"Doug Glancy" wrote in message
...
I have a spreadsheet with some hidden helper columns. One of these
columns is titled "Delete Row Allowed" and contains TRUE or a blank.
True means that the yes, the row can be deleted. In the spreadsheet,
I've defined a name, "boolDeleteItemAllowed" which refers to
"=MySheet!$G1". Thus, the name always tells whether the currently
selected row can be deleted.

In my code I've got the following function, which checks whether row
deletion is allowed. It checks all the rows in the current selection.
It activates one cell in each row to do this. I haven't used Activate
in code for some time, but I'm not sure how to get the relative
reference in each row without it.

Function DeleteRowAllowed() As Boolean
Dim cell As Range
Dim rngActiveCell As Range

DeleteRowAllowed = True
With Workbooks("MyBook.xls").ActiveSheet
'need to set this back at end
Set rngActiveCell = ActiveCell
'check one cell in each row
For Each cell In Selection.Columns(1).Cells
cell.Activate
If CBool(.Names("boolDeleteRowAllowed").RefersToRange .Value) =
False Then
DeleteRowAllowed = False
Exit Function
End If
Next cell
'set back to original ActiveCell
rngActiveCell.Activate
End With
End Function

I don't think it's a big deal in terms of efficiency. As soon as it
hits a blank row it exits and I'll add ScreenUpdating = False. But I am
curious if there's a way to do it without Activate and still keeping the
defined names in the worksheet.

Thanks in advance,

Doug





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Improve code that checks a range of names - currently using Activate

Norman,

Upon reflection, I think that does make the most sense. I'll give the
column a name to make the function more robust.

Thanks,

Doug

"Norman Jones" wrote in message
...
Hi Doug,

Since you define the right to delete a row
according to the value of the corresponding
column G cell, why not use this in your
function rather than a derived condition:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range
Dim rCell As Range
Dim aCell As Range

Set Rng = Selection

For Each rCell In Rng.Columns(1).Cells
Set aCell = Application.Intersect(rCell.EntireRow, _
Rng.Parent.Columns("G:G"))
If aCell.Value = "False" Then
DeleteRowAllowed = False
Exit Function
End If
Next rCell

End Function
'<<=========



---
Regards.
Norman
"Doug Glancy" wrote in message
...
Norman,

Thanks, but that's not it. In each row, the cell value in column G could
be True or not. Some rows, basically detail rows in a bid, can be
deleted, others can not. If multiple rows are selected and any of the
values is not True then the function must return False.

I may be making it more complicated than necessary by referring to the
name - I could do something like what you've done. I am interested
though in keeping as much of the logic in the worksheet as possible, and
so would like to use the name.

Thanks,

Doug

"Norman Jones" wrote in message
...
Hi Doug,

I am not certain that I have understood
your requirement, but, perhaps, try:

'=========
Function DeleteRowAllowed() As Boolean
Dim Rng As Range

Set Rng = Selection.EntireRow.Columns("G:G")
DeleteRowAllowed3= _
Application.CountIf(Rng, "False") 0

End Function
'<<=========



---
Regards.
Norman


"Doug Glancy" wrote in message
...
I have a spreadsheet with some hidden helper columns. One of these
columns is titled "Delete Row Allowed" and contains TRUE or a blank.
True means that the yes, the row can be deleted. In the spreadsheet,
I've defined a name, "boolDeleteItemAllowed" which refers to
"=MySheet!$G1". Thus, the name always tells whether the currently
selected row can be deleted.

In my code I've got the following function, which checks whether row
deletion is allowed. It checks all the rows in the current selection.
It activates one cell in each row to do this. I haven't used Activate
in code for some time, but I'm not sure how to get the relative
reference in each row without it.

Function DeleteRowAllowed() As Boolean
Dim cell As Range
Dim rngActiveCell As Range

DeleteRowAllowed = True
With Workbooks("MyBook.xls").ActiveSheet
'need to set this back at end
Set rngActiveCell = ActiveCell
'check one cell in each row
For Each cell In Selection.Columns(1).Cells
cell.Activate
If CBool(.Names("boolDeleteRowAllowed").RefersToRange .Value) =
False Then
DeleteRowAllowed = False
Exit Function
End If
Next cell
'set back to original ActiveCell
rngActiveCell.Activate
End With
End Function

I don't think it's a big deal in terms of efficiency. As soon as it
hits a blank row it exits and I'll add ScreenUpdating = False. But I
am curious if there's a way to do it without Activate and still keeping
the defined names in the worksheet.

Thanks in advance,

Doug







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
Code to do edit checks when user moves out of a cell Eric @ BP-EVV Excel Programming 1 April 24th 08 04:33 PM
How to improve my code? Jack Excel Programming 2 August 10th 07 09:03 AM
Improve 'Windows(workbook.xls).Activate" statement Hank[_6_] Excel Programming 1 May 2nd 06 02:57 PM
Improve code Gareth Excel Programming 5 April 20th 05 03:41 PM
Help with code that checks if a sheet exists wachen Excel Programming 2 February 10th 04 02:39 AM


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

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

About Us

"It's about Microsoft Excel"