Value in a .Txt Converted to Value in vba

Juve

New Member
Joined
Sep 26, 2011
Messages
3
Hi, I'm ceating a macro that converts a .txt file in an Excel file, but the .txt has the negative numbers with the minus at the right end side, i.e. 242.00-
how could I convert this to the color Red (242.00) ???
Thanks in advance.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Data >Text to Columns has an option for trailing minus in the Advanced settings.
 
Upvote 0
Thank you so much for your quick Response Peter, but do you know how to do this in visual Basics??? I'm Trying this, but it doesn't work because the report shown by my ERP shwos the negative values with the minus sign at the right...

Range("G:G").Select
Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"

Thanks in Advance.
Juve.
 
Upvote 0
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("G" & i)
        If Right(.Value, 1) = "-" Then .Value = -1 * Left(.Value, Len(.Value) - 1)
    End With
Next i
Range("G1:G" & LR).NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End Sub
 
Upvote 0
Great !!! Thank you very much. this instructions work perfectly.
Greetings From Mexico.
Have a good day Peter.

Juve.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top