Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Zero Length Dynamic Range

G'day there One & All,

Stumped again, so here I am once more =). I have a number of
dynamic ranges to handle various lists in my project. I used 2 ranges on
one list to overcome a problem I couldn't find another way around. My
list has entries such as:

Sections <-- Heading
Unknown
Alpha
Bravo
Charlie
etc...

The entries are for testing only, as they will be set by the clients
once this is all sorted out. The only constant entries are the Heading,
and the "Unknown" entry. This doesn't designate an unknown quantity, but
is the string "Unknown". There will be no other entries when deployed.
The users will enter them via a form as required.

I have a dynamic range "Sections" of all entries including "Unknown". A
second one, "srtSections" is for everything under "Unknown" - Alpha -
Charlie in this case. That way my forms ListBox has a RowSource of
"Sections" which includes everything, but when the user adds or deletes
an entry I use "srtSections" and sort alphabetically. This leaves
"Unknown" on top of the ListBox at all times. I use ListBox.Listcount to
ensure that the last entry can't be removed.

All was working fine, until I tested to see how it all went & realised
that although I couldn't delete "Unknown" (correct behaviour), once I
got down to only that entry then "srtSections" was a range of zero
entries and my attempts to reference it raised Global Range errors.

The code is he

Private Sub CommandButton6_Click()
' Add Section
' Set listbox rowsource to null preventing interference with dynamic
' range calculations
Me.ListBox1.RowSource = ""
' Set range variable to address of dynamic range after "Unknown"
' entry
If Application.WorksheetFunction.IsError(Range
("srtSections").Cells.Count) Then
dSht.Range(3, Range("Sections").Column).Value = TextBox3.Text
Else
Set gTgt = Range("srtSections")
' Add value onto bottom of list
Cells(gTgt.Rows.Count + 3, gTgt.Column).Value = TextBox3.Text
End If
' Sort list in alphabetical order
Range("srtSections").Sort Key1:=Range("Sections").Cells(2, 1),
Order1:=xlAscending
' Set listbox rowsource to full list of data as set by dynamic range
' including "Unknown" entry
Me.ListBox1.RowSource = "Data!Sections"

End Sub

I'm trying to add a member to my list, but the "srtSections" reference
has me stuck. How can I test for a range of zero cells without
generating an error? The "IsError" function I used doesn't work as the
error stops everything before I can test for it. Any ideas anyone?

See ya, thanks for thinking about it
Ken McLennan
Qld, Australia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Zero Length Dynamic Range

If gTgt is declared as a global variable and is of type range, then delete
the Dim statement below.
If it is a global variable, but not of type range, then you will need to use
another local variable which is dim'd as range to do the test.

Private Sub CommandButton6_Click()
Dim gTgt as Range
' Add Section
' Set listbox rowsource to null preventing interference with dynamic
' range calculations
Me.ListBox1.RowSource = ""
' Set range variable to address of dynamic range after "Unknown"
' entry
On Error Resume Next
set gTgt = Range("srtSections")
On Error goto 0
If rng is nothing Then
dSht.Range(3, Range("Sections").Column).Value = TextBox3.Text
Else
' Set gTgt = Range("srtSections")
' Add value onto bottom of list
Cells(gTgt.Rows.Count + 3, gTgt.Column).Value = TextBox3.Text
End If
' Sort list in alphabetical order
Range("srtSections").Sort Key1:=Range("Sections").Cells(2, 1),
Order1:=xlAscending
' Set listbox rowsource to full list of data as set by dynamic range
' including "Unknown" entry
Me.ListBox1.RowSource = "Data!Sections"

End Sub


--
Regards,
Tom Ogilvy

"Ken McLennan" wrote in message
.. .
G'day there One & All,

Stumped again, so here I am once more =). I have a number of
dynamic ranges to handle various lists in my project. I used 2 ranges on
one list to overcome a problem I couldn't find another way around. My
list has entries such as:

Sections <-- Heading
Unknown
Alpha
Bravo
Charlie
etc...

The entries are for testing only, as they will be set by the clients
once this is all sorted out. The only constant entries are the Heading,
and the "Unknown" entry. This doesn't designate an unknown quantity, but
is the string "Unknown". There will be no other entries when deployed.
The users will enter them via a form as required.

I have a dynamic range "Sections" of all entries including "Unknown". A
second one, "srtSections" is for everything under "Unknown" - Alpha -
Charlie in this case. That way my forms ListBox has a RowSource of
"Sections" which includes everything, but when the user adds or deletes
an entry I use "srtSections" and sort alphabetically. This leaves
"Unknown" on top of the ListBox at all times. I use ListBox.Listcount to
ensure that the last entry can't be removed.

All was working fine, until I tested to see how it all went & realised
that although I couldn't delete "Unknown" (correct behaviour), once I
got down to only that entry then "srtSections" was a range of zero
entries and my attempts to reference it raised Global Range errors.

The code is he

Private Sub CommandButton6_Click()
' Add Section
' Set listbox rowsource to null preventing interference with dynamic
' range calculations
Me.ListBox1.RowSource = ""
' Set range variable to address of dynamic range after "Unknown"
' entry
If Application.WorksheetFunction.IsError(Range
("srtSections").Cells.Count) Then
dSht.Range(3, Range("Sections").Column).Value = TextBox3.Text
Else
Set gTgt = Range("srtSections")
' Add value onto bottom of list
Cells(gTgt.Rows.Count + 3, gTgt.Column).Value = TextBox3.Text
End If
' Sort list in alphabetical order
Range("srtSections").Sort Key1:=Range("Sections").Cells(2, 1),
Order1:=xlAscending
' Set listbox rowsource to full list of data as set by dynamic range
' including "Unknown" entry
Me.ListBox1.RowSource = "Data!Sections"

End Sub

I'm trying to add a member to my list, but the "srtSections" reference
has me stuck. How can I test for a range of zero cells without
generating an error? The "IsError" function I used doesn't work as the
error stops everything before I can test for it. Any ideas anyone?

See ya, thanks for thinking about it
Ken McLennan
Qld, Australia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Zero Length Dynamic Range

G'day there Tom,

If gTgt is declared as a global variable and is of type range, then delete
the Dim statement below.


Yes, it's a global variable of type range. I got that bit right =)

Private Sub CommandButton6_Click()

....
On Error Resume Next
set gTgt = Range("srtSections")
On Error goto 0
If rng is nothing Then
dSht.Range(3, Range("Sections").Column).Value = TextBox3.Text

....
End Sub


..."is nothing"!!! It's so simple once you point out where I
went wrong <g.

Thanks very much for that. I've not put it to work as yet, as my
wife won't let me play on my 'pooter until we've done the grocery
shopping ...dammit!! (She has some strange idea that groceries don't
just magically appear in the cupboards when you need them).

See ya, and thanks once again,
Ken McLennan
Qld, Australia
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
Range Name Limitations - Max Refers To Length? Barb Reinhardt Excel Discussion (Misc queries) 5 May 19th 23 11:42 AM
Validation length, Range length I think I need to rephrase the question Excel Discussion (Misc queries) 5 September 17th 07 06:29 AM
Macro code to autosum a dynamic length column SlowPoke Excel Discussion (Misc queries) 3 March 31st 06 11:48 PM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Set Range Var with address length over 256 Sandy V[_6_] Excel Programming 9 February 3rd 04 06:23 PM


All times are GMT +1. The time now is 01:24 AM.

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"