Solved

Syntax for FormatCurrency

Posted on 2006-07-21
5
869 Views
Last Modified: 2012-08-13
This is Excel VBA
I have this piece of code I need to add

FormatCurrency to this line in the code
(TextBox2.Text = rng(.ListIndex + 1, 3)

What would be the proper syntax?

Any help would greatly be appreciated

/////////////////////////////////////////////////////////
With ComboBox1
        Set rng = Range(.RowSource)
        TextBox1.Text = rng(.ListIndex + 1, 2)
       (TextBox2.Text = rng(.ListIndex + 1, 3)        
     End With
0
Comment
Question by:ca1358
  • 2
  • 2
5 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17155321
In Excel VBA you can use CCur(value) to convert any value to a currency $#,###.## format.
0
 

Author Comment

by:ca1358
ID: 17156172
Sorry,  I should have told you it is a UserForm.

0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 500 total points
ID: 17159971
Dim curOne As Currency
Dim curTwo As Currency

For i = LBound(ComboBox1.Count) To UBound(ComboBox1.Count - 1)

With ComboBox1
        Set rng = Range(.RowSource)
        curOne = Format(rng(.ListIndex + 1, i) , Currency)       '< --- here
        curTwo = Format(rng(.ListIndex + 1, i), Currency)        '< ---- and here
TextBox1.Text = curOne
TextBox2.Text = curTwo
End With

Next

something like that maybe ? If not then just get rid of the for next loop and replace the i is above with the 2 and 3 you had originally

Hopefully this helps anyway ( With regards to the format function, here is a reference )

http://msdn2.microsoft.com/en-us/library/y006s0cz.aspx

If you need more help post back

0
 

Author Comment

by:ca1358
ID: 17170919
Thank you!
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17171129
np - hopefully it worked for you ( I was just wrote the code out from memory )
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 57
VBA saving file message display 5 64
JSON Response and request in VB6 application 11 418
Looking for VB6 code to read SQL table export it to ascii 8 38
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

770 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