Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default If a cell equals then macro

I have a table with letters "C" or "D" in column G starting G2 & numbers in
column H. I would like the number in a cell to be negative if cell next to it
in column G = "c"
This would apply to all numbers in column starting from H2
The macro below has to be corrected
Sub neg()
If ActiveCell.Offset(0, -1) = "c" Then
ActiveCell.Value = -ActiveCell.Value
End If
End Sub

Pls help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default If a cell equals then macro

Look he

http://www.cpearson.com/excel/Events.aspx

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"transferxxx" wrote in message ...
|I have a table with letters "C" or "D" in column G starting G2 & numbers in
| column H. I would like the number in a cell to be negative if cell next to it
| in column G = "c"
| This would apply to all numbers in column starting from H2
| The macro below has to be corrected
| Sub neg()
| If ActiveCell.Offset(0, -1) = "c" Then
| ActiveCell.Value = -ActiveCell.Value
| End If
| End Sub
|
| Pls help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default If a cell equals then macro

hi
try this...
Sub neg()
Dim r As Range
Dim rd As Range
Set r = Range("H2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "c" Then
r.Value = -r.Value
End If
Set r = rd
Loop
End Sub
regards
FSt1
"transferxxx" wrote:

I have a table with letters "C" or "D" in column G starting G2 & numbers in
column H. I would like the number in a cell to be negative if cell next to it
in column G = "c"
This would apply to all numbers in column starting from H2
The macro below has to be corrected
Sub neg()
If ActiveCell.Offset(0, -1) = "c" Then
ActiveCell.Value = -ActiveCell.Value
End If
End Sub

Pls help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default If a cell equals then macro

Can someone pls correct my code or give me the correct macro as I'm new to
excel
thxs

"Niek Otten" wrote:

Look he

http://www.cpearson.com/excel/Events.aspx

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"transferxxx" wrote in message ...
|I have a table with letters "C" or "D" in column G starting G2 & numbers in
| column H. I would like the number in a cell to be negative if cell next to it
| in column G = "c"
| This would apply to all numbers in column starting from H2
| The macro below has to be corrected
| Sub neg()
| If ActiveCell.Offset(0, -1) = "c" Then
| ActiveCell.Value = -ActiveCell.Value
| End If
| End Sub
|
| Pls help



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default If a cell equals then macro

Perfect - thxs a lot

Do you have another macro which can move the number to the next right hand
column (i.e .Insert Shift:=xlToRight) if cell in G = "c"??
Pls help - thxs



"FSt1" wrote:

hi
try this...
Sub neg()
Dim r As Range
Dim rd As Range
Set r = Range("H2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "c" Then
r.Value = -r.Value
End If
Set r = rd
Loop
End Sub
regards
FSt1
"transferxxx" wrote:

I have a table with letters "C" or "D" in column G starting G2 & numbers in
column H. I would like the number in a cell to be negative if cell next to it
in column G = "c"
This would apply to all numbers in column starting from H2
The macro below has to be corrected
Sub neg()
If ActiveCell.Offset(0, -1) = "c" Then
ActiveCell.Value = -ActiveCell.Value
End If
End Sub

Pls help



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default If a cell equals then macro

Sub neg()
Dim r As Range
Dim rd As Range
Set r = Range("H2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "c" Then
r.Offset(0, 1) = -r.Value
r.ClearContents
End If
Set r = rd
Loop
End Sub


Mike F

"transferxxx" wrote in message
...
Perfect - thxs a lot

Do you have another macro which can move the number to the next right
hand
column (i.e .Insert Shift:=xlToRight) if cell in G = "c"??
Pls help - thxs



"FSt1" wrote:

hi
try this...
Sub neg()
Dim r As Range
Dim rd As Range
Set r = Range("H2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "c" Then
r.Value = -r.Value
End If
Set r = rd
Loop
End Sub
regards
FSt1
"transferxxx" wrote:

I have a table with letters "C" or "D" in column G starting G2 &
numbers in
column H. I would like the number in a cell to be negative if cell next
to it
in column G = "c"
This would apply to all numbers in column starting from H2
The macro below has to be corrected
Sub neg()
If ActiveCell.Offset(0, -1) = "c" Then
ActiveCell.Value = -ActiveCell.Value
End If
End Sub

Pls help



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default If a cell equals then macro

hi again,
add this....
r.Insert Shift:=xlToRight
after....
r.Value = -r.Value

regards
FSt1

"transferxxx" wrote:

Perfect - thxs a lot

Do you have another macro which can move the number to the next right hand
column (i.e .Insert Shift:=xlToRight) if cell in G = "c"??
Pls help - thxs



"FSt1" wrote:

hi
try this...
Sub neg()
Dim r As Range
Dim rd As Range
Set r = Range("H2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "c" Then
r.Value = -r.Value
End If
Set r = rd
Loop
End Sub
regards
FSt1
"transferxxx" wrote:

I have a table with letters "C" or "D" in column G starting G2 & numbers in
column H. I would like the number in a cell to be negative if cell next to it
in column G = "c"
This would apply to all numbers in column starting from H2
The macro below has to be corrected
Sub neg()
If ActiveCell.Offset(0, -1) = "c" Then
ActiveCell.Value = -ActiveCell.Value
End If
End Sub

Pls help

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 a cell equals _, at the next row that equals _, return value fr CathyH Excel Worksheet Functions 10 May 2nd 07 07:53 PM
If cell is left blank, or equals zero, then cell equals a different cell John McMurry Excel Discussion (Misc queries) 3 April 13th 07 01:14 PM
How to create/run "cell A equals Cell B put Cell C info in Cell D abmb161 Excel Discussion (Misc queries) 5 January 26th 06 06:36 PM
if a:a (range) equals january and c:c equals gas then add g:g ($) BCOz Excel Worksheet Functions 4 December 29th 05 07:40 PM
custom filter does not work when selecting 'equals' X AND 'equals' plindman Excel Discussion (Misc queries) 1 June 1st 05 11:29 PM


All times are GMT +1. The time now is 11:53 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"