Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy from AS400


I often need to copy and paste values from an AS400 system. They are
either positive or negative integers. However, when copying and pasting
into an Excel spreadsheet they are copied as strings as opposed to
numeric values. I have a macro that I've been working on, but it
doesn't seem to function properly. Sometime it will work and other
times it won't.

The postive integers would be of the format 3900
and the negative 3900-

Any ideas?

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10"
Dim cell As Range

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
For Each cell In Target
If Right(cell.Value, 1) = "-" Then
cell.Value = Left(cell.Value, Len(cell.Value) - 1) * -1
cell.NumberFormat = "0;<0"
End If
Next cell
End If

ws_exit:
Application.EnableEvents = True
End Sub

Thanks.

-ep


--
inkserious
------------------------------------------------------------------------
inkserious's Profile: http://www.excelforum.com/member.php...o&userid=36734
View this thread: http://www.excelforum.com/showthread...hreadid=565473

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Copy from AS400

You are close but what are you doing about positive numbers? Your code only
seems to want to handle the negatives... Try this...

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10"
Dim cell As Range

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
For Each cell In Target
If IsNumeric(cell.Value) Then
cell.Value = Application.Trim(cell.Value)
If Right(cell.Value, 1) = "-" Then
cell.Value = CInt(Left(cell.Value, _
Len(cell.Value) - 1)) * -1
Else
cell.Value = CInt(cell.Value)
End If
cell.NumberFormat = "0;<0"
End If
Next cell
End If

ws_exit:
Application.EnableEvents = True
End Sub
--
HTH...

Jim Thomlinson


"inkserious" wrote:


I often need to copy and paste values from an AS400 system. They are
either positive or negative integers. However, when copying and pasting
into an Excel spreadsheet they are copied as strings as opposed to
numeric values. I have a macro that I've been working on, but it
doesn't seem to function properly. Sometime it will work and other
times it won't.

The postive integers would be of the format 3900
and the negative 3900-

Any ideas?

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10"
Dim cell As Range

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
For Each cell In Target
If Right(cell.Value, 1) = "-" Then
cell.Value = Left(cell.Value, Len(cell.Value) - 1) * -1
cell.NumberFormat = "0;<0"
End If
Next cell
End If

ws_exit:
Application.EnableEvents = True
End Sub

Thanks.

-ep


--
inkserious
------------------------------------------------------------------------
inkserious's Profile: http://www.excelforum.com/member.php...o&userid=36734
View this thread: http://www.excelforum.com/showthread...hreadid=565473


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy from AS400


It's hanling the postive numbers correctly, but it's still not chanin
the negative numbers from a string to a numeric value.

Confused?

Thanks

-e

--
inkseriou
-----------------------------------------------------------------------
inkserious's Profile: http://www.excelforum.com/member.php...fo&userid=3673
View this thread: http://www.excelforum.com/showthread.php?threadid=56547

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
AS400 copy problem edwardpestian[_25_] Excel Programming 6 June 28th 06 10:50 AM
AS400 transfer via VBA [email protected][_2_] Excel Programming 1 February 24th 06 07:11 PM
Excel and AS400 DB2 database Esperanza[_2_] Excel Programming 0 December 28th 04 09:06 PM
DDE to Query AS400 DB Joseph[_26_] Excel Programming 0 February 9th 04 10:46 PM
SQL against AS400 R. Choate Excel Programming 4 November 7th 03 09:11 PM


All times are GMT +1. The time now is 11:20 PM.

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

About Us

"It's about Microsoft Excel"