[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Worksheetfunction Substitute

Helen

12/20/2006 1:15:00 PM

This macro is supposed to reformat numbers that have a "-" sign in them.
Placing the "-" at the front instead of the end of the number.

I'm getting an error message asking me to define the sub / function, what
have I done wrong?

Sub PurchaseReport()

Dim JDEdata

'Correct JDE Credit Format

Range("G4").Select

For x = 4 To myRows
JDEdata = Range("G" & x)

If Right(JDEdata, 1) = "-" Then

Application.WorksheetFunction = Substitute(JDEdata, "-", , 1)

Application.WorksheetFunction = Substitute(JDEdata, Left(JDEdata), "-" &
Left(JDEdata), 1)

End If
Next x
2 Answers

Bob Phillips

12/20/2006 1:25:00 PM

0

Sub PurchaseReport()

Dim JDEdata

'Correct JDE Credit Format

Range("G4").Select

For x = 4 To myRows
JDEdata = Range("G" & x)

If Right(JDEdata, 1) = "-" Then

JEData = "-" & Left(JEData, Len(JEData) - 1)

End If
Next x
End Sub

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Helen" <Helen@discussions.microsoft.com> wrote in message
news:5B1238B0-F491-4752-9D7F-985484FF6105@microsoft.com...
> This macro is supposed to reformat numbers that have a "-" sign in them.
> Placing the "-" at the front instead of the end of the number.
>
> I'm getting an error message asking me to define the sub / function, what
> have I done wrong?
>
> Sub PurchaseReport()
>
> Dim JDEdata
>
> 'Correct JDE Credit Format
>
> Range("G4").Select
>
> For x = 4 To myRows
> JDEdata = Range("G" & x)
>
> If Right(JDEdata, 1) = "-" Then
>
> Application.WorksheetFunction = Substitute(JDEdata, "-", , 1)
>
> Application.WorksheetFunction = Substitute(JDEdata, Left(JDEdata), "-"
> &
> Left(JDEdata), 1)
>
> End If
> Next x


Tom Ogilvy

12/20/2006 1:25:00 PM

0

Sub PurchaseReport()

Dim JDEdata, x as Long

'Correct JDE Credit Format


For x = 4 To myRows
JDEdata = Range("G" & x)

If Right(JDEdata, 1) = "-" Then
Range("G" & x) = "-" & Left(JDEdata,len(JDEData)-1)
End If
Next x
End sub

If you wanted to use the worksheet function substitute instead of the VBA
function Left and Len, you would do
Range("G" & x) = "-" & Application.WorksheetFunction.Substitute(JDEdata,
"-", , 1)

You could also use

Range("G" & x) = cdbl(JDEdata)

--
Regards,
Tom Ogilvy

"Helen" wrote:

> This macro is supposed to reformat numbers that have a "-" sign in them.
> Placing the "-" at the front instead of the end of the number.
>
> I'm getting an error message asking me to define the sub / function, what
> have I done wrong?
>
> Sub PurchaseReport()
>
> Dim JDEdata
>
> 'Correct JDE Credit Format
>
> Range("G4").Select
>
> For x = 4 To myRows
> JDEdata = Range("G" & x)
>
> If Right(JDEdata, 1) = "-" Then
>
> Application.WorksheetFunction = Substitute(JDEdata, "-", , 1)
>
> Application.WorksheetFunction = Substitute(JDEdata, Left(JDEdata), "-" &
> Left(JDEdata), 1)
>
> End If
> Next x