PC Review


Reply
Thread Tools Rate Thread

Autoadjust range declaration coding when inserting rows

 
 
JW73
Guest
Posts: n/a
 
      27th Apr 2010
Is there a way to auto-adjust the range settings for when you add/delete rows
to an Excel sheet? I'm trying to set up an easy way for end-users to
show/hide blocks of information with a button, and I'm using the code below
for each button:

Private Sub CommandButton1_Click()
Dim myRng As Range
Set myRng = Me.Range("7:12")
myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)
End Sub

Now, the problem is that these blocks of info will have extra lines
inserted, which tends to break all of the coding. Is there some sort of
adjustment to the coding that I can make to accomodate for that situation, or
would the best way be to name each group of rows, and have the range set to
the names, letting Excel auto-adjust the name ranges and keeping the code
from breaking that way?
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      27th Apr 2010
What happens when some rows in the range are hidden and some are not? I
suspect you'll get an error on the line (although I've not tested it).

Barb Reinhardt



"JW73" wrote:

> Is there a way to auto-adjust the range settings for when you add/delete rows
> to an Excel sheet? I'm trying to set up an easy way for end-users to
> show/hide blocks of information with a button, and I'm using the code below
> for each button:
>
> Private Sub CommandButton1_Click()
> Dim myRng As Range
> Set myRng = Me.Range("7:12")
> myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)
> End Sub
>
> Now, the problem is that these blocks of info will have extra lines
> inserted, which tends to break all of the coding. Is there some sort of
> adjustment to the coding that I can make to accomodate for that situation, or
> would the best way be to name each group of rows, and have the range set to
> the names, letting Excel auto-adjust the name ranges and keeping the code
> from breaking that way?

 
Reply With Quote
 
K_Macd
Guest
Posts: n/a
 
      27th Apr 2010
Range naming is probably the best solution (although not fool proof). You can
write code that will find last row in a data region etc but I wouldn't
endorse it, especially in a shared workbook.

People familiar with database record handling experience invariably cringe
when it comes to managing new items in an excel 'table'.
--
Ken
"Using Dbase dialects since 82"
"Started with Visicalc in the same year"


"Barb Reinhardt" wrote:

> What happens when some rows in the range are hidden and some are not? I
> suspect you'll get an error on the line (although I've not tested it).
>
> Barb Reinhardt
>
>
>
> "JW73" wrote:
>
> > Is there a way to auto-adjust the range settings for when you add/delete rows
> > to an Excel sheet? I'm trying to set up an easy way for end-users to
> > show/hide blocks of information with a button, and I'm using the code below
> > for each button:
> >
> > Private Sub CommandButton1_Click()
> > Dim myRng As Range
> > Set myRng = Me.Range("7:12")
> > myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)
> > End Sub
> >
> > Now, the problem is that these blocks of info will have extra lines
> > inserted, which tends to break all of the coding. Is there some sort of
> > adjustment to the coding that I can make to accomodate for that situation, or
> > would the best way be to name each group of rows, and have the range set to
> > the names, letting Excel auto-adjust the name ranges and keeping the code
> > from breaking that way?

 
Reply With Quote
 
JW73
Guest
Posts: n/a
 
      27th Apr 2010
Thanks - I was working on possible solutions all night, and based on the way
the form is set up, and who will be using it, decided that that would
probably have the least chance of breaking.

"K_Macd" wrote:

> Range naming is probably the best solution (although not fool proof). You can
> write code that will find last row in a data region etc but I wouldn't
> endorse it, especially in a shared workbook.
>
> People familiar with database record handling experience invariably cringe
> when it comes to managing new items in an excel 'table'.
> --
> Ken
> "Using Dbase dialects since 82"
> "Started with Visicalc in the same year"
>
>
> "Barb Reinhardt" wrote:
>
> > What happens when some rows in the range are hidden and some are not? I
> > suspect you'll get an error on the line (although I've not tested it).
> >
> > Barb Reinhardt
> >
> >
> >
> > "JW73" wrote:
> >
> > > Is there a way to auto-adjust the range settings for when you add/delete rows
> > > to an Excel sheet? I'm trying to set up an easy way for end-users to
> > > show/hide blocks of information with a button, and I'm using the code below
> > > for each button:
> > >
> > > Private Sub CommandButton1_Click()
> > > Dim myRng As Range
> > > Set myRng = Me.Range("7:12")
> > > myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)
> > > End Sub
> > >
> > > Now, the problem is that these blocks of info will have extra lines
> > > inserted, which tends to break all of the coding. Is there some sort of
> > > adjustment to the coding that I can make to accomodate for that situation, or
> > > would the best way be to name each group of rows, and have the range set to
> > > the names, letting Excel auto-adjust the name ranges and keeping the code
> > > from breaking that way?

 
Reply With Quote
 
JW73
Guest
Posts: n/a
 
      27th Apr 2010
Nope - if some of the lines are visible, it hides the whole group upon click

"Barb Reinhardt" wrote:

> What happens when some rows in the range are hidden and some are not? I
> suspect you'll get an error on the line (although I've not tested it).
>
> Barb Reinhardt
>
>
>
> "JW73" wrote:
>
> > Is there a way to auto-adjust the range settings for when you add/delete rows
> > to an Excel sheet? I'm trying to set up an easy way for end-users to
> > show/hide blocks of information with a button, and I'm using the code below
> > for each button:
> >
> > Private Sub CommandButton1_Click()
> > Dim myRng As Range
> > Set myRng = Me.Range("7:12")
> > myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)
> > End Sub
> >
> > Now, the problem is that these blocks of info will have extra lines
> > inserted, which tends to break all of the coding. Is there some sort of
> > adjustment to the coding that I can make to accomodate for that situation, or
> > would the best way be to name each group of rows, and have the range set to
> > the names, letting Excel auto-adjust the name ranges and keeping the code
> > from breaking that way?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Inserting rows conditionally, how to work with shifting range nj Microsoft Excel Programming 2 19th Sep 2006 09:38 PM
inserting and deleting blank rows in selected range =?Utf-8?B?c3Nh?= Microsoft Excel Misc 2 23rd Oct 2004 12:27 PM
Inserting a formula into blank rows in a varying range Phil Platt Microsoft Excel Misc 3 5th Aug 2004 10:23 PM
differences in declaration and instantiation coding Mark Kamoski Microsoft ASP .NET 5 3rd Sep 2003 06:18 PM
Keeping a range constant when inserting rows Jeff Olson Microsoft Excel Misc 4 28th Aug 2003 12:49 AM


Features
 

Advertising
 

Newsgroups
 


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