Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Turn +ve to -ve & vice versa.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sinner - 27 Mar 2008 13:32 GMT
Hi,

How do I do that in VB?
For each value 'abc' is found in columnL starting from cell L2 then
turn values in columnE starting C2 positive to negative (vice versa)

Thanks
cht13er - 27 Mar 2008 13:58 GMT
> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks

Try pasting this in a new module and hitting F5:

Private Sub SwitchSign()
   Dim iLastRow As Integer
   Dim strAddress As String

   ActiveCell.SpecialCells(xlLastCell).Select
   strAddress = ActiveCell.Address

   Do Until IsNumeric(strAddress) = True And Left(strAddress, 1) <>
"$"
       strAddress = Mid(strAddress, 2)
   Loop

   iLastRow = CInt(strAddress)

   Cells(1, 12).Select

For iCounter = 1 To iLastRow - 1
    If ActiveCell.Offset(iCounter, 0).Value = "abc" Then
          ActiveCell.Offset(iCounter, -9).Value = (-1) *
ActiveCell.Offset(iCounter, -9).Value
    End If
Next iCounter
End Sub

Hope this helps, let me know if you have any problems!
Chris
Jean-Yves TFELT - 27 Mar 2008 14:29 GMT
Hi,

A bit shorter

Sub test()
Dim cl As Range
For Each cl In Range("L2", Range("L2").End(xlDown))
If cl.Value = "abc" Then cl.Offset(0, -9).Value = cl.Offset(0, -9).Value *
(-1)
Next cl
End Sub

Regards
Jean-Yves

On Mar 27, 8:32 am, Sinner <ims...@gmail.com> wrote:
> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks

Try pasting this in a new module and hitting F5:

Private Sub SwitchSign()
   Dim iLastRow As Integer
   Dim strAddress As String

   ActiveCell.SpecialCells(xlLastCell).Select
   strAddress = ActiveCell.Address

   Do Until IsNumeric(strAddress) = True And Left(strAddress, 1) <>
"$"
       strAddress = Mid(strAddress, 2)
   Loop

   iLastRow = CInt(strAddress)

   Cells(1, 12).Select

For iCounter = 1 To iLastRow - 1
    If ActiveCell.Offset(iCounter, 0).Value = "abc" Then
          ActiveCell.Offset(iCounter, -9).Value = (-1) *
ActiveCell.Offset(iCounter, -9).Value
    End If
Next iCounter
End Sub

Hope this helps, let me know if you have any problems!
Chris
Mike H - 27 Mar 2008 14:50 GMT
Middling length but it doesn't destry formulas

Sub test()
Dim myrange As Range
LastRow = Cells(Cells.Rows.Count, "L").End(xlUp).Row
Set myrange = Range("L2:L" & LastRow)
For Each c In myrange
   If c.Value = "abc" Then
       If Not c.Offset(0, -9).HasFormula Then
           c.Offset(0, -9).Value = c.Offset(0, -9).Value * (-1)
       End If
   End If
Next
End Sub

Mike

> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks
Mike H - 27 Mar 2008 14:54 GMT
I should have included this to catch text

For Each c In myrange
    On Error Resume Next

Mike

> Middling length but it doesn't destry formulas
>
[quoted text clipped - 20 lines]
> >
> > Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.