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 18th, 2002, 08:39 AM   #1
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

I have this workbook that works fine on my computer(using 2000) but I e-mailed the workbook to a guy (using 97) and he gets an error message on this line:
Cells(c.Row + 1, 4).Rows.EntireRow.Insert

Can anyone give me some reasons why? Or help in fixing it so that it will work properly.

Thanks,

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

viper
viper is offline   Reply With Quote
Old May 18th, 2002, 12:22 PM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Viper,

What's the line of code that sets "c"?
This may be the true culprit, it looks like the problem stems from "c" not being set properly.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old May 18th, 2002, 12:30 PM   #3
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Right on Mark, if c is a range, the following fires in '97:


Sub inSrt()
Dim c As Range
Set c = ActiveCell
c.EntireRow.Insert
End Sub

__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old May 18th, 2002, 12:41 PM   #4
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

here is the code, I got it from TsTom to help add a row if a cell is empty.

Dim c
For Each c In Range("CodeRange")
ActiveSheet.Unprotect ("password")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
If Cells(c.Row, 4) <> "" Then
Cells(c.Row + 1, 4).Rows.EntireRow.Insert
Cells(c.Row + 1, 4) = TextBox4

thanks,

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

viper
viper is offline   Reply With Quote
Old May 18th, 2002, 12:54 PM   #5
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Assuming your data is in the the same column as CodeRange, try the following:


Sub test()
Dim c As Range
For Each c In Range("CodeRange")
ActiveSheet.Unprotect ("password")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
If c.Value <> "" Then
c.Offset(1, 0).EntireRow.Insert 'Change 0 is necessary (same column)
c.Offset(1, 0).Value = TextBox4 'Change 0 is necessary (same column)
End If
End If
Next c
ActiveSheet.Protect ("password")
End Sub


_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-19 00:12 ]
NateO is offline   Reply With Quote
Old May 19th, 2002, 12:06 AM   #6
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Thanks Nate,

But it added a new row in column A and inserted the figure from the textbox.

What Tom's did was check column D, if it was blank then it passed his code and inserted the figure via my code, but if the cell in column D wasn't blank then it inserted a row below the cell and then inserted the figure into the new cell in column D.

Here is my complete code I am using.

If Not IsNumeric(TextBox1) Then
MsgBox "Need a Number"
TextBox1.SetFocus
Exit Sub
End If
Dim c
For Each c In Range("CodeRange")
ActiveSheet.Unprotect ("password")
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
If Cells(c.Row, 4) <> "" Then
Cells(c.Row + 1, 4).Rows.EntireRow.Insert
Cells(c.Row + 1, 4) = TextBox4
Range("e9").Copy
Range("e10:e130").Select
Selection.PasteSpecial Paste:=xlFormulas

Range("D9:D130").Select
Selection.TextToColumns Destination:=Range("D9"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
Range("E9").Select
Else
Cells(c.Row, 4) = TextBox4
Range("D9:D130").Select
Selection.TextToColumns Destination:=Range("D9"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
Range("E9").Select
End If
Exit For
End If
Next
ActiveSheet.Protect ("password")

If TextBox1.Value < 1 And TextBox1.Value > 85 Then
MsgBox "Range 1 to 85"
TextBox1.SetFocus
Exit Sub
End If

Thanks,

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

viper
viper is offline   Reply With Quote
Old May 19th, 2002, 01:32 AM   #7
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Hello Viper, if CodeRange is in column A and you want to work with data in column D, change:

If c.Value <> "" Then
c.Offset(1, 0).EntireRow.Insert 'Change 0 is necessary (same column)
c.Offset(1, 0).Value = TextBox4 'Change 0 is necessary (same column)
End If

to

If c.Offset(, 3).Value <> "" Then
c.Offset(1, 0).EntireRow.Insert 'Change 0 is necessary (same column)
c.Offset(1, 3).Value = TextBox4 'Change 0 is necessary (same column)
End If


The second parameter of offset (3) lets Excel know that while we're using column A, we want to look at the data 3 columns right of our current position.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-19 00:35 ]
NateO is offline   Reply With Quote
Old May 20th, 2002, 06:55 PM   #8
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

The code above still makes no difference. The code still doesn't insert the new row at the correct location. The code I do use for this workbook works excellent but only with Excel 2000, I can't get it to work with 97. I'm at a loss as to what to do.
__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old May 20th, 2002, 07:24 PM   #9
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Quote:
The code still doesn't insert the new row at the correct location.
Viper, inserting a row affects every column, you can't insert a row in the wrong column, just the wrong row.

So, this is proving to be interesting with the partial code listing. The code below is what I meant by changing the offset. Again, I'm assuming "CodeRange" is in column A, of course this will not work if that's not true, which column is "CodeRange" in?


Dim c As Range, d As Range
Set d = [d9:d130]
ActiveSheet.Unprotect ("password")
For Each c In Range("CodeRange") 'Is CodeRange in Column A?
Debug.Print c.Value
If c.Value = Val(TextBox1) Then
If c.Offset(, 3).Value <> "" Then
c.Offset(1, 0).EntireRow.Insert
c.Offset(1, 3).Value = TextBox4
Range("e9").Copy
Range("e10:e130").PasteSpecial Paste:=xlFormulas
d.TextToColumns Destination:=Range("D9"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
Else: c.Offset(0, 3).Value = TextBox4
d.TextToColumns Destination:=Range("D9"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
End If
Exit For
End If
Next


I used the offset for row insertion yesterday on a program for my buddy (in xl '97) and it worked well, the only reason I'm mentioning it.

_________________
Cheers, NateO

[ This Message was edited by: nateo on 2002-05-20 19:16 ]
NateO is offline   Reply With Quote
Old May 20th, 2002, 08:36 PM   #10
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Nate,

I appreciate all you're doing for this, I just pasted your code into the workbook and still not working. What it does now is when i enter the data and click okay it gives me the error "no data to parse". so it didn't copy textbox4 to the cell. I have pasted my data into this so I hope it looks okay. But if you look Column A is the "CodeRange" which is the numbers that textbox1 will contain. Column b is for discription only and C is for fixed data, Column D is where the data from Textbox4 will be placed if textbox1 matches the code from Column A So if D9 is not blank and the user inputs a 1 into textbox1 then when okay is pressed the code should insert a new row because D9 is already occupied.

Sorry just couldn't get it to look good. Couldn't paste it need more practice.



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

viper

[ This Message was edited by: viper on 2002-05-20 19:38 ]

[ This Message was edited by: viper on 2002-05-20 19:39 ]

[ This Message was edited by: viper on 2002-05-20 19:41 ]

[ This Message was edited by: viper on 2002-05-20 19:45 ]
viper 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 07:47 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