![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Feb 2003
Posts: 240
|
I have a download in which some of the numbers in the download have a minus sign to the right of the value.
For example I get 23000- 1400- how can I move the minus sign to the left? I want the value to be -23000 or -1400. I would like this in a macro of some kind. The data is in Range("B1:B2000"). Thanks |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 42,696
|
|
|
|
|
|
|
#3 |
|
MrExcel MVP, Administrator
Join Date: Feb 2002
Location: The act or process of locating.
Posts: 13,528
|
|
|
|
|
|
|
#4 |
|
Join Date: Jan 2003
Location: Cleveland, OH
Posts: 282
|
From www.xl-logic.com comes this handy macro:
Code:
Sub DashMasher()
' To convert 15- to -15.
On Error Resume Next
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set TextCells = Cells.SpecialCells(xlCellTypeConstants, xlTextValues)
n = TextCells.Count
For Each Cell In TextCells
x = Cell.Value
If Right(x, 1) = "-" Then
x = -Left(x, Len(x) - 1)
Cell.Value = x
End If
c = c + 1
Application.StatusBar = "Percent Complete: " & Int(c / n * 100) & "%"
Next Cell
Application.StatusBar = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
P |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Jul 2002
Posts: 39,281
|
Another way:
Code:
Sub Test()
Dim Rng As Range
Columns("C:C").Insert
Set Rng = Range("C1:C" & Range("B1").End(xlDown).Row)
Rng.FormulaR1C1 = _
"=(SUBSTITUTE(RC[-1],""-"","""")+0)*IF(RIGHT(RC[-1],1)=""-"",-1,1)"
Rng.NumberFormat = "General"
Rng.Copy
Rng.Offset(, -1).PasteSpecial xlPasteValues
Rng.Offset(, -1).PasteSpecial xlPasteFormats
Columns("C:C").Delete
End Sub
|
|
|
|
|
|
#6 | |
|
Join Date: Feb 2003
Posts: 240
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
Banned
Join Date: Sep 2006
Location: Bombay, India
Posts: 3,263
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|