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 Mar 7th, 2002, 01:40 AM   #1
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

Sub row_inserter()
I got the code below from a colleague to insert a row.

I'm trying to understand how it all fits together and was wondering if someone could explain how/ what the Offset command does, as it seems to be something pretty common.

Thanks in advance.
Matt


Range("A1").Select
Do Until ActiveCell = ""
If ActiveCell.Offset(1, 0) <> "" Then
ActiveCell.Offset(1, 0).EntireRow.Insert
ElseIf ActiveCell.Offset(1, 0) = "" Then
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

mrowe is offline   Reply With Quote
Old Mar 7th, 2002, 01:50 AM   #2
Derek
Board Regular
 
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
Default

Hi
The offset function is a way of referring to a cell, or range, that is "offset" from the cell or range in question. Usually it is applied to the activecell. The amount of offset is shown within brackets, the first number refers to number of rows (positive is down, negative is up) and the number after the comma refers to the number of columns (positive is right, negative is left) to move from the active (or reference) cell. So ActiveCell.Offset(1, 0) refers to the cell in the row immediately below the active cell but in the same column as the active cell.
Hope this makes sense
regards
Derek


[ This Message was edited by: Derek on 2002-03-07 00:52 ]
Derek is offline   Reply With Quote
Old Mar 7th, 2002, 01:56 AM   #3
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

'Activates A1 in the Activesheet
Range("A1").Select

'Start of a do loop where this loop routine
'will loop until the activecell = ""
Do Until ActiveCell = ""
'If the activecell offset by ([1] Row down ,[0]on the same column)
'does not = "" then
If ActiveCell.Offset(1, 0) <> "" Then
'select this the cells Row and insert an entire row
ActiveCell.Offset(1, 0).EntireRow.insert
'otherwise...if the activecell offset by ([1] Row down ,[0]on the same column)
'equals ""....
ElseIf ActiveCell.Offset(1, 0) = "" Then
'then select this cell
ActiveCell.Offset(1, 0).Select
End If
'Now loop = goto the the start of the loop and evaluate the loop condition
Loop

End Sub

'NB: just inserts a row @ A2 ??? any use ??

ivan



Ivan F Moala is offline   Reply With Quote
Old Mar 7th, 2002, 01:58 AM   #4
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi mrowe

What is you are wanting to do? The code you have will only insert 1 row at row 2!


Dave Hawley is offline   Reply With Quote
Old Mar 7th, 2002, 02:04 AM   #5
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

Hi Dave,

I know the code only inserts a row, but it was more to get an understanding of how it works so I can apply it to other routines.

Cheers
(ps - are you from Australia?)
Matt
mrowe is offline   Reply With Quote
Old Mar 7th, 2002, 02:23 AM   #6
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Matt

Yes I am! is my accent that strong )




Dave Hawley is offline   Reply With Quote
Old Mar 7th, 2002, 02:28 AM   #7
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

No so, just your website.... I'm from there also but live/work in London.

Always interested in work at home - got any tips on that???
mrowe is offline   Reply With Quote
Old Mar 7th, 2002, 03:19 AM   #8
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

I worked in London myself for a year about 13 years ago (god I am getting old). Loved and hated it! Loved London, hated getting on the Tube every day.

What sort of work do you do and where abouts in Oz you from? I'm about 200 km south of Perth.




Dave Hawley is offline   Reply With Quote
Old Mar 7th, 2002, 03:23 AM   #9
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

I'm from Victoria, but lived in QLD and have been here for about 6 years.
I'm called a Business Analysist.... what ever... but we look after the companies Sales Order system, finance system (CODA) and Client Mgmt System along with Business Objects Reporting, Sybase stuff and SQL7 - also do some on the side web design and excel projects for internal things.

Thinking about comming home next year with the wife but don't know what the work situation is like.....
mrowe is offline   Reply With Quote
Old Mar 7th, 2002, 03:47 AM   #10
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

As far as I'm aware the enconomy is booming along at the moment. Not too sure what the job market is like though as I'm self-employed.
Dave Hawley 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 05:28 AM.


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