Computing.Net > Forums > Office Software > Macro - Inserting rows into Excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Macro - Inserting rows into Excel

Reply to Message Icon

Name: GiveMePatience
Date: September 15, 2005 at 08:50:31 Pacific
OS: XP
CPU/Ram: 1.8ghz/512mb
Comment:

Not sure if there is a solution to this problem or not, but here's what I'm attempting to do:

I've designed a worksheet in which users are able to add aditional rows to different categories by clicking on an "Insert Row" command button. Assigned macro reads as the following:

Sub Button44_Click()
Rows("28:28").Select
Selection.Insert Shift:=x1Down
End Sub

On worksheets with only one category that may need additional rows, this works perfectly. However, on worksheets that include different categories (i.e. under colums B, C, D, etc.), I have multiple "Insert Row" command buttons. Problem is, once the command button at the top of the sheet is clicked (several times), it thows off all the other command buttons. For example, "Insert Row" #2 reads:

Sub Button45_Click()
Rows("35:35").Select
Selection.Insert Shift:=x1Down
End Sub

But the problem is, once the first command button is used, the second command button is inserting rows on Row35, but should adjust to how many rows were inserted with the first command button (does this make sense?).

Again, I don't know if this is possible or not, but any help would be appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: Grok Lobster
Date: September 15, 2005 at 10:09:34 Pacific
Reply:

Well, one thing you could do is set up a counting cell off somewhere that the user won't see and increment it in your Button44 macro and then reset it with the Button45 macro.
A better way is to key off of information that is always in the workbook to find the appropriate row location for insertion. Something like the following:
Set NameAddress = Cells.Find(What:=KeyWord, after:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If NameAddress Is Nothing Then
MsgBox "Not found"
Else:

NextRow = NameAddress.Row + 1
MsgBox NextRow
End If

I did not test the above code, it is only provided as an example.


0

Response Number 2
Name: GiveMePatience
Date: September 15, 2005 at 13:27:54 Pacific
Reply:

Thanks Lobster!

I had to tweak a little bit and change a few things around and play with it, but made it work perfectly! Thanks for the help.

GMP


0

Response Number 3
Name: GiveMePatience
Date: September 15, 2005 at 13:33:30 Pacific
Reply:

FYI,

Used the following:

Set NameAddress = Cells.Find("INSERTYOURTEXTHERE", after:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
NameAddress.Select
ActiveCell.Offset(1, 0).EntireRow.Insert

For each of the command button macros I entered different combinations of text in cells that wouldn't be used by the individual (and protected them); as well as masked the text (font color = background color) so it is invisible to the user.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Macro - Inserting rows into Excel

Excel Macro - Seqentially # Rows www.computing.net/answers/office/excel-macro-seqentially-rows/6914.html

Delete rows in Excel www.computing.net/answers/office/delete-rows-in-excel/2171.html

MS Excel - Change Row into Column? www.computing.net/answers/office/ms-excel-change-row-into-column/4491.html