Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default Swap trailing minus to leading

I just imported a very large text file where the numbers were formatted with
a trailing sign so I now have sells which look like this 000478-. I'd like to
change that so thet they are -478. I've been doing it manually, but I figured
a macro to search the entire spreadsheet would be much more efficient. All of
the numbers are 7 characters with the 8th position being the sign. There are
also many numbers that were either 0 or positive which imported just fine, so
I need to leave them alone. Any suggestions as to how best solve this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Swap trailing minus to leading

I would just put a formula in a cell on the same line as the number, for
example if your 000478- was in cell A1 then in cell B1 type:-

=IF(RIGHT(A1,1)="-",-INT(LEFT(A1,LEN(A1)-1)),INT(A1))

Now just copy this down to the bottom of your data. If necessary, copy the
column and paste the values over the top of the data in the original column
and delete your formula column.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk


"Curt" wrote:

I just imported a very large text file where the numbers were formatted with
a trailing sign so I now have sells which look like this 000478-. I'd like to
change that so thet they are -478. I've been doing it manually, but I figured
a macro to search the entire spreadsheet would be much more efficient. All of
the numbers are 7 characters with the 8th position being the sign. There are
also many numbers that were either 0 or positive which imported just fine, so
I need to leave them alone. Any suggestions as to how best solve this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Swap trailing minus to leading

You could try the following using the VBA route:

Sub MoveMinus()

Dim rngCell As Range
Dim lngLastRow As Long
Dim lngLastCol As Long
Dim wksSheet As Worksheet

Application.ScreenUpdating = False
Set wksSheet = ActiveSheet

With wksSheet
'Get last row and column populated
lngLastRow = .Cells.Find("*", .Range("A1"), xlFormulas, , xlByRows,
xlPrevious).Row
lngLastCol = .Cells.Find("*", .Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column

For Each rngCell In .Range(.Cells(1, 1), .Cells(lngLastRow,
lngLastCol))
If Right(rngCell.Value, 1) = "-" Then
rngCell.Value = "-" & Left(rngCell.Value, Len(rngCell.Value)
- 1)
End If
Next
End With

Application.ScreenUpdating = True

End Sub


Regards,

Chris



"Curt" wrote:

I just imported a very large text file where the numbers were formatted with
a trailing sign so I now have sells which look like this 000478-. I'd like to
change that so thet they are -478. I've been doing it manually, but I figured
a macro to search the entire spreadsheet would be much more efficient. All of
the numbers are 7 characters with the 8th position being the sign. There are
also many numbers that were either 0 or positive which imported just fine, so
I need to leave them alone. Any suggestions as to how best solve this?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Swap trailing minus to leading

On Fri, 17 Oct 2008 07:41:00 -0700, Curt
wrote:

I just imported a very large text file where the numbers were formatted with
a trailing sign so I now have sells which look like this 000478-. I'd like to
change that so thet they are -478. I've been doing it manually, but I figured
a macro to search the entire spreadsheet would be much more efficient. All of
the numbers are 7 characters with the 8th position being the sign. There are
also many numbers that were either 0 or positive which imported just fine, so
I need to leave them alone. Any suggestions as to how best solve this?


If you have a reasonably modern version of Excel, there is an option for
handling trailing minus signs in the Data/Text-to-columns wizard. This option
is found at Step 3 after selecting the "Advanced" button.

Select your data
Data/TExt-to-Columns
Next
Next
Advanced
Select the trailing minus option
OK
Finish
--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Swap trailing minus to leading

I would use the Text to Columns method as Ron points out.

But for a VBA solution.................

Sub Negsignleft()
Dim Cell As Range
Dim rng As Range
''move minus sign from right to left on entire worksheet
On Error Resume Next
Set rng = ActiveSheet.Cells. _
SpecialCells(xlCellTypeConstants, xlTextValues)
On Error GoTo 0
For Each Cell In rng
If IsNumeric(Cell.Value) Then
Cell.Value = CDbl(Cell.Value) * 1
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Fri, 17 Oct 2008 07:41:00 -0700, Curt
wrote:

I just imported a very large text file where the numbers were formatted with
a trailing sign so I now have sells which look like this 000478-. I'd like to
change that so thet they are -478. I've been doing it manually, but I figured
a macro to search the entire spreadsheet would be much more efficient. All of
the numbers are 7 characters with the 8th position being the sign. There are
also many numbers that were either 0 or positive which imported just fine, so
I need to leave them alone. Any suggestions as to how best solve this?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed width parsing with trailing minus Dave Peterson Excel Programming 3 September 3rd 08 11:22 PM
trailing minus via135 Excel Worksheet Functions 10 November 25th 07 06:51 PM
CHANGE TRAILING MINUS TO BRACKETS OR PRECEEDING MINUS Socal Analyst looking for help Excel Discussion (Misc queries) 2 May 12th 06 07:17 PM
Importing values w/trailing minus signs RWN Excel Discussion (Misc queries) 1 December 11th 04 05:05 AM
leading or trailing quotes Clint[_3_] Excel Programming 1 April 15th 04 02:41 PM


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"