Here's what I want to do. I have a caption that changes every time someone uses the app. The caption is a number... and now it appears like a regular number 123456 ... I want to add "," every 3 digits and I really don't know how to do it because the number doesn't have the same number of digits every time... (I want it to be 123,456 instead of 123456 or 1,234,567... and so on). Thanks!
I'm assuming you're setting the caption in code, so you can use VBA's format function to do this:
Me.MyLabel.Caption = Format(MyNum, "#,##0")
Related
I am needing to customize cells with simple thousands format, like 1000, without any separator or decimal.
However, I wish to remove text fonts other than a number when they are input.
For example, I want to input 120118, however in my paper from which I am copying that figures, it is formatted as a date, thereby 12/01/18. I am needing Excel to simply keep it as 120118 after typing, removing the slash (/). I have seen similar settings in access queries.
Have you tried simply pasting only the cell value with:
Selection.PasteSpecial Paste:=xlPasteValues
Or just clear the cell format and format it again with your desired format.
Try:
Selecting the range
Home > Number > Number Format (or Ctrl+1 I think) > Custom
Enter ddmmyy
Okay
Can be done programmatically e.g.
Thisworkbook.worksheets("Sheet1").range("A1:A50").numberformat = "ddmmyy"
The above would only be a visual/cosmetic change and the internal value of each cell would still be a date (technically a number) for calculation purposes.
However, if I've misunderstood and you instead want to go from the date 21 Jan 2018 to the number 210118, I think you would need to get the range's value(s), format as DDMMYY string, then clng() - or maybe (DD*10000) + (MM*100) + (YY) might work, then format as "000000" to preserve leading zeros.
I have this statement nested in an IF-Statement under a scenario. I would like it to format column 2 into a Accounting number without decimal places. How can this be done using VB.net? The current code gives me ex: 1,000,000.00 on an input of 1000000. I noticed excel has buttons for adding or subtracting decimal places. Could these be called within VB.net? Thanks!
Lo.ListColumns("Column2").DataBodyRange(CurrentRow).NumberFormat = "ACCOUNTING"
Try the following
Lo.ListColumns("Column2").DataBodyRange(CurrentRow).NumberFormat = "#0,000.00"
You may find help in this Article
From what i understand you want, you can do:
math.floor(*insert the value or variable you want here*)
What that does is it changes the number in the parameter to the biggest integer lower than the parameter.
Hope this works :)
I have a database with all the U.S. tariff codes that I need to format.
The numbers appear as:
010129
Whereas I need them to appear as:
0101.29
I have tried to use custom formatting to match the decimals with ####.?? but it does not work.
The database contains 19,423 rows of data; therefore, if there is a better way to format the numbers using VBA, I will gladly take that response as well. Thank you!
Because you have Text rather than Numbers, reformatting is not enough. With your data in A1, in B1 enter:
=LEFT(A1,5) & "." & MID(A1,6,3)
and copy down. For example:
EDIT#1
If the double-quotes do not appear in the data then use:
=LEFT(A1,4) & "." & MID(A1,5,2)
See:
I am using a textbox in vb.net but the input should be an hour format for example, "13h30".
How can I enfprce this by a user? When he puts the first 2 digits like 13 then automaticly the appl. puts a "h" between? Or is there a better solution?
thx
If you are using WinForms then you could use a masked textbox with a mask of 00h00. This doesn't work too well if they subsequently want to edit the value they have entered though as the rightmost digits are shifted left if you do a backspace. You may be better off making a user control
How can i format quantity value in crystal report like if the value is 5, then just show as 5. If the value is 5.25, then show as 5.25. So which format should i use for that?
Thanks.
Right-click on the element and go into the formatting menu. I think what you want will be an option.
Instead of displaying it as a numeric value, write a function, MyStr$, which converts to string depending on whether the number is integer or not. BTW, a good way to check for integrality is a test of the form:
ABS(x -Truncate(x)) < EPS
where EPS is a small value, like 0.001 (depending on the accuracy you need, increase or decrease this)
Use this "conditional format formula":
If Truncate(CurrentFieldValue) = CurrentFieldValue
Then
0
Else
Length(ToText(ToNumber(StrReverse(ToText(Abs(CurrentFieldValue) - Truncate(Abs(CurrentFieldValue)),8,"",""))) / 10,0,""))
Go to the numeric report field, rightclick, choose "Format Field", choose "Number" tab, click "Customize" button. Put the formula above in the format formula ("X+2" button) for the format options "Decimals" and "Rounding".
BTW: In the formula you'll notice the number 8. This is the maximum expected number of decimals; if you think you'll encounter more decimals in your report then simply change 8 to a higher number.