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 29th, 2002, 04:45 PM   #1
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default


I am filling an excel spreadsheet with values and formats (using .value and .numberformat) from vb6 using MS Excel 9.0 Object Library.

The values and formats are applied to the cells, but the value does not become formatted with the specified format. If you go into each cell manually and press enter, each value becomes formatted.

Is there a function i can use to rectify this. I have tried: range("F3").parse and this seems to work although sometimes cuts the values short if plain text with .numberformat="@".

I have programmed Excel VBA and VB6 for many years, and do not see any obvious mistake on my part, am assuming it is a bug in the object library.

Thanks.

daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 10:27 PM   #2
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default


also, have problems with using:

.range(cells(x1,y1),cells(x2,y2)).blablabla

does anybody else experience these problems with the excel 9.0 object library or is it just me? The problem in my first note is my most desperate. Thanks.
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 10:37 PM   #3
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi

Are you using the numberformat="@" in all the cells as this is a Text format and will cause problems with numbers.

You could try using:

Columns("F:F").Calculate

To force a recalculation, which what happens when you re-enter the number. But I feel you problems lies in the original format you are using.

What can't you do with:
range(cells(x1,y1),cells(x2,y2)).blablabla


Dave Hawley is offline   Reply With Quote
Old Mar 29th, 2002, 10:57 PM   #4
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

Thanks Dave, but i feel there are inherent problems with the coding of the dll.

When I use range(cells(x1,y1),cells(x2,y2)) i get the following runtime:

Routine Error '1004':
Method 'Cells' of object '_Global' failed.

...i have a workaround for this anyhow, that works okay, where i put

range(rangename(x1,x2,y1,y2)) ...and use function rangename to calculate the string required to make the statement work. messy but doesn't bother me.

The other problem, however, is more taxing as i do not have a workaround. I have just tested .Calculate and it doesn't do it for me. Basically, I have SQL backend giving output in the form:

Rowx : integer
Colx : integer
Valx : varchar(50) string
Formatx : varchar(50) string

and so a (what should be) simple VB6 routine takes this output and populates the spreadsheet with the following code:

xlsheet.cells(rowx,colx).value=data.valx
xlsheet.cells(rowx,colx).numberformat=data.formatx

where values tie up with the formats (which I have tested using "@" with text values, "0.00" with numericals, "d-mmm-yy" with date values). Now the formats and values both hit the cells, as when you open the sheet up manually and hit enter on each cell the data gets formatted. My problem is i don't know how to do this programmatically.

Probably sounds silly, but .parse works except for slight bug that it abbreviates some text strings. Do you know what .parse is and how it works (i do not have help files, or at least not until the office opens again on Tuesday!). It may be easiest to adjust this so that it does the job.

Thanks again, D.
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 11:28 PM   #5
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

D, when you get the Rutime error, what are values are x1,y1 etc holding, They must be Integers.


Are you certain that you numeric cells are being formatted as numbers. before entering the number check it's cell Format, I wouldn't be suprised if they are Text. You may also be better off formatting the entire Column as "General" and letting Excel decide.


Dave Hawley is offline   Reply With Quote
Old Mar 29th, 2002, 11:32 PM   #6
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

just basic test using

.range(cells(1,1),cells(2,2)).font.italic=true

fails (but 1 time in ten it will work!).



Have tried the format/value insertion in various ways. The workbook is new so opens with default general, and i have tried to do format then value, or value then format, or even format then value then format again, but to no avail... as i say .parse is the only thing that seems to come close...

does anyone have help files & can tell me what .parse does???

thanks once again, D.
daleyman is offline   Reply With Quote
Old Mar 29th, 2002, 11:42 PM   #7
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi D

Here is the VBE help on Parse

Parses a range of data and breaks it into multiple cells. Distributes the contents of the range to fill several adjacent columns; the range can be no more than one column wide.

Syntax

expression.Parse(ParseLine, Destination)

expression Required. An expression that returns a Range object.

ParseLine Optional Variant. A string that contains left and right brackets to indicate where the cells should be split. For example, "[xxx][xxx]" would insert the first three characters into the first column of the destination range, and it would insert the next three characters into the second column. If this argument is omitted, Microsoft Excel guesses where to split the columns based on the spacing of the top left cell in the range. If you want to use a different range to guess the parse line, use a Range object as the ParseLine argument. That range must be one of the cells that's being parsed. The ParseLine argument cannot be longer than 255 characters, including the brackets and spaces.

Destination Optional Variant. A Range object that represents the upper-left corner of the destination range for the parsed data. If this argument is omitted, Microsoft Excel parses in place.

END OF EXCEL HELP

You say that x1,y1 are just basic text? They should be Integers.

2 Other 'maybe' are:

Columns(1) = Columns(1).Value

With Sheets("Sheet1").Range("A1", Range("A65536").End(xlUp))
.SpecialCells(xltypenumbers).NumberFormat = "0.00"
End With



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 04:29 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