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 8th, 2002, 08:47 PM   #1
donh
Board Regular
 
Join Date: May 2002
Posts: 88
Default

I am trying to get a macro that will work off of keystrokes.

Does anyone know how to write a macro for this?

at any cell:
copy
down arrow
shift, control, down arrow
shift, up arrow
paste
control, down arrow

If there is data in rows 4,12,14,18 and titles in row 1 every time I try this, the range is constant Range("A4:A12")

This defeats the purpose of "control, down arrow" to find the next row with data. If the next row that has data is row 14 this macro will overwrite it because the range is 8 rows.

I am trying to fill in rows with data where the data is at varying rows and the data is different at each row. The data comes to me different each time (the next time say rows
7,11,20,25) and is usually over 1,000 rows deep.

I also would like to know how to do it with the up arrow too.

at any cell:
copy
up arrow
shift, control, up arrow
shift, down arrow
paste
control, down arrow
control, down arrow

Does anyone have any ideas?
donh is offline   Reply With Quote
Old May 8th, 2002, 09:17 PM   #2
MrExcel
.
 
MrExcel's Avatar
 
Join Date: Feb 2002
Location: Akron, Ohio USA
Posts: 789
Default

The answer will be in the .End method.

ActiveCell.End(xlDown) will be like your Ctrl+Shift+DownArrow

ActiveCell.End(xlUp) will be like your Ctrl+Shirt+UpArrow

If you start in A4, and need to go down a row, then this will do it:
ActiveCell.Offset(1, 0).Select

You can also specify a range by specifying the first and last cells of the range. This bit of code will select the blank cells:
Range(ActiveCell.Offset(1, 0), ActiveCell.offset(1, 0).End(xldown).offset(-1, 0)).Select

Bill
__________________
Preview my latest book for Free
MrExcel is offline   Reply With Quote
Old May 8th, 2002, 09:21 PM   #3
MrExcel
.
 
MrExcel's Avatar
 
Join Date: Feb 2002
Location: Akron, Ohio USA
Posts: 789
Default

You will also find that what you are trying to do is similar to filling in the blank cells in a pivot table. Follow the instructions in this tip of the week to do this quickly through the user interface:
http://www.mrexcel.com/tip004.shtml

You can also automate this with the following VBA:
Code:
    Range("A4:A100").SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    Range("A4:A100").Copy
    Range("A4:A100").PasteSpecial xlPasteValues
Bill

_________________
MrExcel.com Consulting

[ This Message was edited by: MrExcel on 2002-05-08 20:22 ]
MrExcel is offline   Reply With Quote
Old May 8th, 2002, 09:22 PM   #4
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Very nice, MrExcel lends a hand. Since we're on the same thread, I'll add: excellent board sir (kudos). If nobody minds, I'll add to the foray:

Donh, I swear I'm not leaving you out to dry, I just needed a break after a long day at the office, some Maple Leaf Hockey and a cold beverage (er two). In any case the code at the following post has some serious merits for what you want to accomplish:

http://www.mrexcel.com/board/viewtop...c=7672&forum=2

I didn't write it as straight forward as possible, and for that I apologize. I'm trying to demonstrate how to select cells and ranges without [actually] selecting cells, making it more difficult to interpret but worthwile for you to review.

But allow me to break it down (to the nitty gritty), with selections (you don't need this but to duplicate key strokes). To move down:

Code:
activecell.offset(1,0).select
Offset has two parameters row, then range (e.g., if you want to offset the active cell one row: offset(1,0), one column: offset (0,1) ).

To move up, or right, make the offset negative. E.g., one row up is:

Code:
activecell.offset(-1,0).select
.

Two more points of interest. To select a multi-cell ranges in VBA, you can use:

Code:
Range(range1:range2).select
This will select every cell between the two ranges, as I used in the earlier post.

The other code implimented is the cell(row numer, column number). This allows you to work with row numbers and column numbers (whereas columns are typically defined by a letter).

Your data sheet is tough to interpret from afar, hopefullly between this explanation and an earlier example of these techniques it will help you progress towards success.

Otherwise, post back. But keep posting under the same post, so that people know what's out there and how to build from there (instead of scratch).

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-08 20:40 ]
NateO is offline   Reply With Quote
Old May 8th, 2002, 09:34 PM   #5
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Alrighty, no disrespect to the founder of this website meant with my post, I was typing while MrExcel posted (is my post long enough?). Also, review the pivot table possibility, after reviewing your array of data, it may be much easier to consolidate as needed. Incidentally, you can record pivot table set-ups as a macro. Good hunting.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-08 20:41 ]
NateO is offline   Reply With Quote
Old May 9th, 2002, 03:34 PM   #6
donh
Board Regular
 
Join Date: May 2002
Posts: 88
Default

WOW!!!

The “filling in the blanks tip” from MrExcel has to be the slickest thing I have ever seen. I had 3 spreadsheets that all were over 52,000 rows deep. I needed to fill at least 50,000 of those rows x 2 columns x 3 spreadsheets and in a manner of seconds over 300,000 rows were filled.

With a little bit of thinking I was able to get the tip to fill “up” as needed.

I am forever indebted.

Thanks
donh 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:16 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