Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Trouble using macros to insert rows

Hi,

I have 3 buttons that insert new rows in 3 different sections of the
spreadsheet. Whenever I insert a row, the subsequent rows referenced in
the other macros are now off. For example, if I add 2 new rows to
sections 1 with button 1, buttons 2 and 3 will now add rows 2 rows
above where I want them. I tried coding a variable to track how many
times each button is pressed, but I don't know how to add that number
to a row. They are different types. I'm a novice with VB so that could
be problem. Any help you can give would be much appreciated.

THANKS!!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Trouble using macros to insert rows

Please post the code for each button, and tell us what range is section
1, 2, and 3. Also, you say "I tried coding a variable to track how
many times each button is pressed, but I don't know how to add that
number to a row." Did you try this to troubleshoot the Button 1-2-3
problem, or is this a different requirement?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Trouble using macros to insert rows


Dave O wrote:
Please post the code for each button, and tell us what range is section
1, 2, and 3. Also, you say "I tried coding a variable to track how
many times each button is pressed, but I don't know how to add that
number to a row." Did you try this to troubleshoot the Button 1-2-3
problem, or is this a different requirement?


Thanks for the response.

The code is very simple, just recorded it:

Sub addMilestone1()

Rows("20:20").Select
Selection.Insert Shift:=xlDown
Range("A20").Select
End Sub

Sub addMilestone2()

Rows("21:21").Select
Selection.Insert Shift:=xlDown
Range("A21").Select
End Sub

Sub addMilestone3()

Rows("22:22").Select
Selection.Insert Shift:=xlDown
Range("A22").Select
End Sub

As you can see the rows to select are hardcoded. Hence, when I use
addMilestone1, the other 2 milestone macros won't change the row they
should be inserted at.

For example: if I run addMilestone1 twice, it will add 2 rows at row
20. It will shift all other rows below it down by 2. So, when I go to
run the other macros, they insert 2 rows above where they should.

I tried to track the number of times a button was pressed so that I
could add that number to the row in each macro to offset for any rows
that have been inserted. Problem here is that I don't know how to add
anumber to Rows("20:20").Select. If I put the variable in place of the
20's, it says that it is a type mismatch which makes sense because it
is looking for a row and I am handing it a number.

Hope that answered your questions, I really appreciate any help you can
offer.

Getch

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Trouble using macros to insert rows


Dave O wrote:
Please post the code for each button, and tell us what range is section
1, 2, and 3. Also, you say "I tried coding a variable to track how
many times each button is pressed, but I don't know how to add that
number to a row." Did you try this to troubleshoot the Button 1-2-3
problem, or is this a different requirement?



Here is a pic of exactly what it looks like:

http://dodownload.filefront.com/6110...5cfac07958d16d

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Trouble using macros to insert rows

Here's one way to do it: create a named range for each of the three
sections: I've called them Section1, Section2, and Section3 for this
example. Each named range should be 1 row above the row each section
starts on. Then change your code to the code that follows. The named
ranges for sections 2 and 3 will move, and thereby they are dynamic,
when rows are inserted above them, which will relieve the need to keep
track of how many rows have been inserted. Note: if you use a
different named range naming format, you'll need to change the code to
match.

Let me know what you think- will this do it for you?


Sub addMilestone1()
Application.Goto Reference:="Section1"
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Insert
Range("a" & Selection.Row).Select
End Sub

Sub addMilestone2()
Application.Goto Reference:="Section2"
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Insert
Range("a" & Selection.Row).Select
End Sub

Sub addMilestone3()
Application.Goto Reference:="Section3"
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Insert
Range("a" & Selection.Row).Select
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default Trouble using macros to insert rows

THANK YOU!!!!!!!!!!!!!!!

I've worked with named ranges before. Genious to use them in this
manner, never would have thought of that. Works PERFECTLY! I don't know
how to thank you, but I appreciate this so much.

Take care!
Getch

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Trouble using macros to insert rows

No worries, glad to help. The feedback is plenty of thanks!

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
I need to know how to insert rows easliy. ie hot key etc... wc Excel Discussion (Misc queries) 2 August 3rd 06 05:21 PM
Insert blank rows repeatedly between every data row in Excel Cool Excel Discussion (Misc queries) 2 January 9th 06 12:10 PM
Insert Rows in Balance Sheet Template Teacher_Becky New Users to Excel 2 November 21st 05 02:15 AM
Protect Worksheet but allow to insert or delete rows Bob L Hilliard Excel Discussion (Misc queries) 2 June 9th 05 02:08 PM
Auto Insert of Rows Gar3th Excel Worksheet Functions 0 January 6th 05 08:33 PM


All times are GMT +1. The time now is 10:41 PM.

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"