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 9th, 2002, 11:30 AM   #1
goplacesuk
New Member
 
Join Date: May 2002
Location: Bob
Posts: 3
Default

I need to import data in a flat file on a daily basis, each file is an addition to the previous one. I have recorded a
macro that works fine for the first import, but as the destination is a named cell it only works once. How can I change
the macro so it writes the data to the active cell rather than a named one?.
regards
Bob
goplacesuk is offline   Reply With Quote
Old May 9th, 2002, 01:20 PM   #2
kkknie
Board Regular
 
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
Default

If I assume your main worksheet starts at row 1 and has at data in every row (at least one column with data), you can find out where the last row is by using:

Range("A1").select
iRow = Selection.CurrentRegion.Rows.Count + 1

The value in the variable iRow will be the number of rows in your worksheet + 1 for the next blank row.

Use this information in the start range of your import function (not sure exactly how you have this set up, so I cannot give an exact answer). If the function has a range in it for the start (like Range("A1:A1, you could simply use:

Range(Cells(irow,1),Cells(iRow,1))

where the 1 is whatever column was in your range function.

Good luck and sorry about the sloppy answer. I'm headed to the golf course in 5 minutes and didn't have time for much more.

K
kkknie is offline   Reply With Quote
Old May 9th, 2002, 04:15 PM   #3
goplacesuk
New Member
 
Join Date: May 2002
Location: Bob
Posts: 3
Default

Thanks for the reply,
I have tried various combinations of your formula but still cannot get it to work.

This is the macro:

Sub importc()

With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:ordersc.dat", _
Destination:=Range("A408"))
.Name = "orders_360"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
End Sub

The problem is with the line:

With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:ordersc.dat", _
Destination:=Range("A408"))
I need to replace ("A408")) with the active cell.

I have managed to get over this with this:

pos = InputBox("ENTER CELL")
With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:ordersg.dat", _
Destination:=Range(pos))

but this is a bit cumbersome, I am sure there must be a better way.

regards
Bob
goplacesuk is offline   Reply With Quote
Old May 9th, 2002, 05:11 PM   #4
goplacesuk
New Member
 
Join Date: May 2002
Location: Bob
Posts: 3
Default

kkknie.

I have managed to get over the problem.
Simple really with your help.

for anyone who is interested this done the job:

irow = Selection.CurrentRegion.Rows.Count
Dim nrow
nrow = "A" & irow
With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:ordersc.dat", _
Destination:=Range(nrow))

This now writes the data to the active row.

regards
Bob
goplacesuk 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 06:40 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