MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 12th, 2002, 11:26 AM   #1
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

If I am in cell A45 and I want a macro to insert a new row based on a user response how would I write that?

I need for the macro to be able to insert a new row based on what ever the users current position is if needed. If in cell A45 and need new row then insert new row, if in cell A65 and need new row then insert new row.

I am trying to make a sheet with a userform that the user will input a code number(1-85) and then enter the data from the invoice, but they want to be able to have multiple items under the same code so I thought if after the intial data is transferred I'd ask if they have another item for the same code, if so I'd bring back the userform and after they entered the second items data it would insert a new row under the previous item(sub category)and then put that data into the new line.

But I can't figure out how to write it:

Thanks,
__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old May 12th, 2002, 11:45 AM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hey Viper.
I'm not real clear on what you need.
This will insert a row below the "Active" cell.

Cells(ActiveCell.Row + 1, 1).Rows.Insert

Tom
Tom Schreiner is offline   Reply With Quote
Old May 12th, 2002, 12:07 PM   #3
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,388
Default

Since you need user interaction, an input box might do the job. Also, you can give the users the option to enter as many rows as they want, with a macro like this:

Sub InsertRow()
Dim Rquan
Rquan = InputBox("Enter the number of rows required, based on" & vbCrLf & _
"how many items you have for this code number:", "How many rows do you need?")
If Rquan = "" Then Exit Sub
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(Rquan - 1, 0)).EntireRow.Insert
End Sub

Any help?

_________________
Tom Urtis

[ This Message was edited by: Tom Urtis on 2002-05-12 11:10 ]
Tom Urtis is offline   Reply With Quote
Old May 12th, 2002, 05:27 PM   #4
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Thanks for your suggestions. But I think I'm doing this the hard way. Here is my code(Thanks again Tom):
If TextBox1.Value > 0 And TextBox1.Value < 86 Then
ActiveSheet.Cells(TextBox1.Value +7,4).Value = TextBox4.Text
How would I change/add to this so that it will insert a row if the cell above is not empty. Right now, with the code above everytime I make a new entry it will overwrite the previous entry, I would like to just have it insert a new row so that I can see all costs under the same code.
__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old May 12th, 2002, 07:53 PM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi Viper...
I think I recognize that code from another thread. If we're going to be inserting rows, then you might need another approach. Could use find, a for..each loop, ect...
Post the code from your userform and maybe summarize what you are needing to do.
Thanks,
Tom
Tom Schreiner is offline   Reply With Quote
Old May 12th, 2002, 09:27 PM   #6
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

This is what I'm trying to do.

item code description cost
01 nails 25.00
02 lumber 500.00

now if they have another item for item code 01 I need for a macro to insert a row under the top one so that it looks like this.

item code description cost
01 nails 25.00
hammer 15.00
02 lumber 500.00

here's the code:

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.Unprotect ("password")
If Not IsNumeric(TextBox1) Then
MsgBox "Need a Number"
TextBox1.SetFocus
Exit Sub
End If
'insert user data from cost box to sheet
If TextBox1.Value > 0 And TextBox1.Value < 86 Then

ActiveSheet.Cells(TextBox1.Value + 7, 4).Value = _
TextBox4.Text
Else
MsgBox "Range 1 to 85"
TextBox1.SetFocus
Exit Sub
End If
ActiveSheet.Protect ("password")
'copy invoice number and invoice total to next sheet
Sheets("Invoice listing").Activate
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
ActiveSheet.Unprotect ("password")
Cells(NextRow, 1) = TextBox5.Value
Cells(NextRow, 2) = TextBox4.Value
ActiveSheet.Protect ("password")
'check for other entries
Sheets("Sheet1").Activate
Msg = ("Enter another invoice?")
Config = vbYesNo + vbQuestion
Ans = MsgBox(Msg, Config)
If Ans = vbYes Then
TextBox1.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
End If
If Ans = vbNo Then
Unload UserForm1
End If
End Sub

And yes I think I will need sometype of loop until the user clicks no.
But it will only need to insert a new row when one or more entries are made in the same item code.

So if item code 01 has three items each will need to listed separately.

item code description cost
01 nails 25.00
insert new row for next item
hammer 15.00
insert new row if another item
screws 10.00

_________________
Soon I hope to be answering alot of these questions instead of asking them.

viper

[ This Message was edited by: viper on 2002-05-12 20:44 ]
viper is offline   Reply With Quote
Old May 13th, 2002, 09:14 PM   #7
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi Viper...
I'm having a difficult time following you here.
Questions:
Are you listing a database of sorts containing a complete list of available items on the active sheet in a column in rows 1 to 85?
The user selects an item from a userform and an invoice is built on a seperate sheet?
Sorry to pester you for deatails, but I don't have a good enough grasp on your structure to really offer you any help.
Post LOTS of details.
Thanks,
Tom
Tom Schreiner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT -4. The time now is 02:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes