Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Turn +ve to -ve & vice versa.

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Turn +ve to -ve & vice versa.

On Mar 27, 8:32*am, Sinner wrote:
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


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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Turn +ve to -ve & vice versa.

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

"cht13er" wrote in message
...
On Mar 27, 8:32 am, Sinner wrote:
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


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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Turn +ve to -ve & vice versa.

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

"Sinner" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Turn +ve to -ve & vice versa.

I should have included this to catch text

For Each c In myrange
On Error Resume Next

Mike

"Mike H" wrote:

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

"Sinner" wrote:

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

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
If Hours 0, If Volume <= 0,(and vice-versa) then.... Steve Excel Worksheet Functions 4 November 21st 09 01:30 PM
Hexadecimal to Decimal (and vice versa) Toria Excel Worksheet Functions 5 January 22nd 09 09:43 PM
Turn off recalculate to send data into TM1 and vice versa. bhinbest Excel Worksheet Functions 0 June 19th 07 07:41 PM
FirstName, LastName and vice versa Bob Excel Worksheet Functions 3 October 27th 06 06:54 PM
Outlook task from xls or vice versa wahur[_2_] Excel Programming 0 August 26th 05 02:37 PM


All times are GMT +1. The time now is 01:38 AM.

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"