[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2004-10-28
3
Medium Priority
?
2,540 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
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month8 days, 2 hours left to enroll

607 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