Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Resizing a Range

Good Afternoon,

I have a macro that each time someone clicks the "Insert Summary Lines"
button I want it to resize the original range. The macro will copy two lines
in the current range and insert them, right now I can only get the code to
select the range and not save it, so when you click on the button again it
reverts back to the old method. Here is my code:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub

Any suggestions
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Resizing a Range

You may want to use a dynamic range to do this. Take a look here for more
information

http://peltiertech.com/WordPress/200...ynamic-charts/
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Katie" wrote:

Good Afternoon,

I have a macro that each time someone clicks the "Insert Summary Lines"
button I want it to resize the original range. The macro will copy two lines
in the current range and insert them, right now I can only get the code to
select the range and not save it, so when you click on the button again it
reverts back to the old method. Here is my code:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub

Any suggestions

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Resizing a Range

I sthe code doing the copying corectly? the copy and Inserts look all wrong
which is making it hard to find out how to fix the code. Get the copy and
Insert working first and then repost.

"Katie" wrote:

Good Afternoon,

I have a macro that each time someone clicks the "Insert Summary Lines"
button I want it to resize the original range. The macro will copy two lines
in the current range and insert them, right now I can only get the code to
select the range and not save it, so when you click on the button again it
reverts back to the old method. Here is my code:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub

Any suggestions

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Resizing a Range

Add this just before the Workbook.Save statement
ActiveWorkbook.Names.Add _
Name:="Summary_Sheet", _
RefersTo:="Summary!" &
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Address

This basically redefines the range of Summary_Sheet

"Katie" wrote:

Good Afternoon,

I have a macro that each time someone clicks the "Insert Summary Lines"
button I want it to resize the original range. The macro will copy two lines
in the current range and insert them, right now I can only get the code to
select the range and not save it, so when you click on the button again it
reverts back to the old method. Here is my code:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub

Any suggestions

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resizing a Range


Joel,

The code is typed correctly. I have to places within this spreadsheet
that I am copying lines and inserting them. This part works fine, I am
even able to select the new range however it does not save it so when
the user clicks to insert another line it reverts back to the original
range definition.
I have several parts going into this macro therefore you were seeing a
few variables that didn't need to be there. I will show you what it
looks like now:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
'Range("First_Cell").Activate
'Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
'Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Resizing a Range

Awaiting your feeback on my post...

"butrfly_kis3" wrote:


Joel,

The code is typed correctly. I have to places within this spreadsheet
that I am copying lines and inserting them. This part works fine, I am
even able to select the new range however it does not save it so when
the user clicks to insert another line it reverts back to the original
range definition.
I have several parts going into this macro therefore you were seeing a
few variables that didn't need to be there. I will show you what it
looks like now:

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range
Dim Sample As Range



NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Set Sample = Range("Summary_Sheet")
Worksheets("Summary").Activate
'Range("First_Cell").Activate
'Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
'Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ThisWorkbook.Save
End Sub


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Resizing a Range

Sheeloo,

When I type it just as you have it I receive a 1004 object error code. Am I
missing something?

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range




NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ActiveWorkbook.Names.Add([Name:="Summary_Sheet"], [RefersTo:="Summary!" &
Range("Summary_Sheet").Resize(Rowsize:=NumRows,Col umnSize:=NumColumns]).Address
ThisWorkbook.Save
End Sub

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resizing a Range


Sheeloo,

I tried entering it the way you have it typed in the message but
receive a 1004 object error code...any ideas?

This is exactly what it looks like:
Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range




NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ActiveWorkbook.Names.Add([Name:="Summary_Sheet"], [RefersTo:="Summary!"
&
Range("Summary_Sheet").Resize(Rowsize:=NumRows,Col umnSize:=NumColumns]).Address
ThisWorkbook.Save
End Sub


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Resizing a Range

It is one VBA statement so all should be in one line unless there is an "_"
at the end of the line...

I have added line numbers... to avoid confusion due to wrap in the post.
1. ActiveWorkbook.Names.Add _
2. Name:="Summary_Sheet", _
3. RefersTo:="Summary!" &
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Address

"Katie" wrote:

Sheeloo,

When I type it just as you have it I receive a 1004 object error code. Am I
missing something?

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer
Dim Summary_Sheet As Range




NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 4
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows, ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ActiveWorkbook.Names.Add([Name:="Summary_Sheet"], [RefersTo:="Summary!" &
Range("Summary_Sheet").Resize(Rowsize:=NumRows,Col umnSize:=NumColumns]).Address
ThisWorkbook.Save
End Sub

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resizing a Range


Sheeloo,

That will run with no error but when I try to run it again I found out
it deleted the summary sheet range.

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer




NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 2
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ActiveWorkbook.Names.Add _
Name:="Summary_Sheet", _
RefersTo:="Summary!" & Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Address
ThisWorkbook.Save
End Sub


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Resizing a Range

Strange...
I tested it many times before posting... It updated the range everytime.

Can you send me the file?

Add @hotmail.com to to_sheeloo to get my id.

Yes, id has a 'to' too :-)

"butrfly_kis3" wrote:


Sheeloo,

That will run with no error but when I try to run it again I found out
it deleted the summary sheet range.

Sub Insert_Rows()
Dim NumRows As Integer
Dim NumColumns As Integer
Dim S As Integer




NumberofRows = Range("Summary_Sheet").Rows.Count
NumberofColumns = 15
S = 0
Worksheets("Summary").Activate
Range("First_Cell").Activate
Set Sum_Description = Worksheets("Summary").Columns("C").Rows("7")
Range(Sum_Description.Address).Activate
Range("Summary_Line").Copy
Range("Summary_Line").Insert shift:=xlShiftDown, copyorigin:=True
S = S + 2
Range("Total_Summary").Copy
Range("Total_Summary").Insert shift:=xlShiftDown, copyorigin:=True

Do Until (NumberofRows = NumRows)
If (S 0) Then
NumRows = NumberofRows + S
NumColumns = NumberofColumns
Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Select
End If
NumberofRows = NumberofRows + S
Loop
ActiveWorkbook.Names.Add _
Name:="Summary_Sheet", _
RefersTo:="Summary!" & Range("Summary_Sheet").Resize(Rowsize:=NumRows,
ColumnSize:=NumColumns).Address
ThisWorkbook.Save
End Sub


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resizing a Range


I have just sent it.

Thanks for you help.
Katie


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Resizing a Range

I have sent the updated file back.

I should NOT have added the .address at the end...
also prepending "Summary!") was also not required.

right code is pasted below;
I have added line numbers... to avoid confusion due to wrap in the post.
1. ActiveWorkbook.Names.Add _
2. Name:="Summary_Sheet", _
3. RefersTo:=Range("Summary_Sheet").Resize(Rowsize:=N umRows,
ColumnSize:=NumColumns)

"butrfly_kis3" wrote:


I have just sent it.

Thanks for you help.
Katie


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Resizing a Range


Sheeloo,

Thanks for you help, it is working perfectly.


--
butrfly_kis3
------------------------------------------------------------------------
butrfly_kis3's Profile: http://www.thecodecage.com/forumz/member.php?userid=8
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23750

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
Resizing range Barb Reinhardt Excel Programming 1 November 10th 06 08:35 PM
resizing a range don Excel Programming 3 February 19th 06 12:23 PM
resizing a range don Excel Programming 3 February 18th 06 03:00 AM
Resizing my range - End row Jacqui Excel Programming 3 November 1st 05 06:00 PM
resizing a range Tim Kredlo Excel Programming 1 September 27th 05 08:30 PM


All times are GMT +1. The time now is 04:51 AM.

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"