Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to format a cell or a Range in Excel From vb6.0

Posted on 2004-10-28
3
Medium Priority
?
2,300 Views
Last Modified: 2008-02-01
Hi,

I would like to format a cell or Range of Excel from vb6.0 Code,

As the way we could do in
 (Excel -> Right click->  Format cells-> Then Number tab->Then Under category List box-> Number)

My sample program is given Below:
 

    Dim objExcel As Excel.Application
    Dim objWorkBook As Excel.Workbook
    Dim objSheet As Excel.Worksheet
   

    Set objExcel = New Excel.Application
    objExcel.Visible = True

   

    Set objWorkBook = objExcel.Workbooks.Add
    Set objSheet = objWorkBook.Worksheets(1)
   

    With objSheet
     

        .Cells(1, 3) = CboProject.Text
        .Cells(1, 3).Font.Bold = True
        .Cells(3, 3) = CboReportFor.Text
        .Cells(3, 3).Font.Bold = True
        .Cells(4, 3) = "Date From : " & cboUsage_DateFrom & " to " & cboUsage_DateTo

        .Cells(4, 3).Font.Bold = True

        .cells(X,Y).Format (?)

    End With

 ........................

Can you help me on that?
Thanks in Advance
Muntasir

0
Comment
Question by:muntasirrahman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Assisted Solution

by:DeltaDaan
DeltaDaan earned 100 total points
ID: 12442061
This should work :

.cells(X, Y).NumberFormat = "$##,###.00"

Ofcourse you can change the # and fill in the format you want to have.

Good Luck
0
 
LVL 9

Expert Comment

by:p_sie
ID: 12442398
Record a macro in Excel and you have the exact code you need!
0
 
LVL 35

Accepted Solution

by:
mvidas earned 100 total points
ID: 12444993
If you wanted to show the actual window at runtime you could use
 objExcel.Dialogs(xlDialogFormatNumber).Show

DeltaDaan has the right syntax with the .NumberFormat, using a "0" will force Excel to show that digit, even if its a zero. "#" will display the number if it exists
If the value is 1234.56 then
 "#,###" will show 1,235
 "#,###.#" will show 1,234.6
 "0,000,000.000" will show 0,001,234.560
etc.

p_sie is right though, you can just record a macro, format the number as you want it to show, then look at the code to see what the numberformat is.

Matt
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question