Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting does not work 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have coded a certain format in VBA but when the macro is run I get a number with 13 numbers to the right of the decimal point. Is there a way of resolving this? I have highlighted in red the offending line

Code:
Columns("K").Select

        With Selection
         .NumberFormat = "0.00"
         .Columns.Autofit
         .VerticalAlignment = xlCenter
         .HorizontalAlignment = xlRight
        End With
        
        
        For R2 = 4 To LR
        
         Retrace1 = 0.03
         Retrace2 = Retrace1 * 100
         BUY = (Range("H" & R2) * Retrace1)
         BUY1 = Range("H" & R2) + BUY
         BUY2 = Range("D" & R2)
         BUY3 = BUY2 - Range("J" & R2)

       
        Range("J1").Value = Retrace2 & "% Retracement"
        If BUY < BUY2 Then Range("J" & R2).Value = BUY1
        If BUY1 < BUY2 Then Range("I" & R2).Value = BUY1
        [Red] Range("K" & R2).Value = ("Buy at " & BUY3 & " or less")[/Red]
        
         
        
         Next R2
 

Hi,

You have formatted NUMBERS.

Your value is TEXT...
Code:
Range("K" & R2).Value = ("Buy at " & BUY3 & " or less")
the BUY3 value, that is sandwiched in there is converted to text, all 13 or so digits.

Here's how to 'fix' this text...
Code:
Range("K" & R2).Value = ("Buy at " & Format(BUY3,"0.00") & " or less")
BTW, because you are writing TEXT, this statement does absolutely NOTHING in column K...
Code:
        With Selection[b][s]
         .NumberFormat = "0.00"[/s][/b]
...




Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I deleted the NumberFormat = "0.00" as sugested and I added the Format code as sugested and your code works great! Thanks !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top