Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Compare columns and move data based on a value and change the sign to negative

To all the programming Guru's out there.
I'm trying to make some VB code that will look at a column and if the
value in that column is greater than 0,
move it to the corresponding column to the left and change the sign to
a negative.
Below is an example of data I am using.
Column A B C
CASH 125.00 0
CASH2 0 180.00
CASH3 0 12,000.00

So in the rows with cash2 and cash 3 I would like to move those values
to column B and make
them negative.
Below is the code I have that will move data based on an input box but
I have to put the value I want to change in there, and it will not
make the value negative. I would rather have this input box be set to
not equal to what I put in the box, but I'm not sure that an Input box
is designed to do that? Any help would be greatly appreciated.
Thank you

Sub Move_Stuff()
Dim topCel As Range
Dim bottomCel As Range

whatval = InputBox("Enter a Value")

Set topCel = Range("C1")
Set bottomCel = Cells((800), topCel.Column).End(xlUp)
If bottomCel.Row = topCel.Row Then
With Range(topCel, bottomCel)
Set c = .Find(whatval, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
Do
c.Cut Destination:=c.Offset(0, -1)
Set c = .FindNext
Loop While Not c Is Nothing
End If
End With
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Compare columns and move data based on a value and change the sign

Sub switch()
lstRw = Cells(Rows.Count, 3).End(xlUp).Row
Set myRng = Range("$C$2:$C" & lstRw)
For Each c in myRng
If c 0 Then
cRng = c.Address
Range(cRng).Offset(0, -1) = Range(cRng).Value *v(-1)
Range(cRng) = 0
End If
Next
End Sub


" wrote:

To all the programming Guru's out there.
I'm trying to make some VB code that will look at a column and if the
value in that column is greater than 0,
move it to the corresponding column to the left and change the sign to
a negative.
Below is an example of data I am using.
Column A B C
CASH 125.00 0
CASH2 0 180.00
CASH3 0 12,000.00

So in the rows with cash2 and cash 3 I would like to move those values
to column B and make
them negative.
Below is the code I have that will move data based on an input box but
I have to put the value I want to change in there, and it will not
make the value negative. I would rather have this input box be set to
not equal to what I put in the box, but I'm not sure that an Input box
is designed to do that? Any help would be greatly appreciated.
Thank you

Sub Move_Stuff()
Dim topCel As Range
Dim bottomCel As Range

whatval = InputBox("Enter a Value")

Set topCel = Range("C1")
Set bottomCel = Cells((800), topCel.Column).End(xlUp)
If bottomCel.Row = topCel.Row Then
With Range(topCel, bottomCel)
Set c = .Find(whatval, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
Do
c.Cut Destination:=c.Offset(0, -1)
Set c = .FindNext
Loop While Not c Is Nothing
End If
End With
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Compare columns and move data based on a value and change the

It works better without the typo.

Sub switch()
lstRw = Cells(Rows.Count, 3).End(xlUp).Row
Set myRng = Range("$C$2:$C" & lstRw)
For Each c in myRng
If c 0 Then
cRng = c.Address
Range(cRng).Offset(0, -1) = Range(cRng).Value * (-1)
Range(cRng) = 0
End If
Next
End Sub



"JLGWhiz" wrote:

Sub switch()
lstRw = Cells(Rows.Count, 3).End(xlUp).Row
Set myRng = Range("$C$2:$C" & lstRw)
For Each c in myRng
If c 0 Then
cRng = c.Address
Range(cRng).Offset(0, -1) = Range(cRng).Value * (-1)
Range(cRng) = 0
End If
Next
End Sub


" wrote:

To all the programming Guru's out there.
I'm trying to make some VB code that will look at a column and if the
value in that column is greater than 0,
move it to the corresponding column to the left and change the sign to
a negative.
Below is an example of data I am using.
Column A B C
CASH 125.00 0
CASH2 0 180.00
CASH3 0 12,000.00

So in the rows with cash2 and cash 3 I would like to move those values
to column B and make
them negative.
Below is the code I have that will move data based on an input box but
I have to put the value I want to change in there, and it will not
make the value negative. I would rather have this input box be set to
not equal to what I put in the box, but I'm not sure that an Input box
is designed to do that? Any help would be greatly appreciated.
Thank you

Sub Move_Stuff()
Dim topCel As Range
Dim bottomCel As Range

whatval = InputBox("Enter a Value")

Set topCel = Range("C1")
Set bottomCel = Cells((800), topCel.Column).End(xlUp)
If bottomCel.Row = topCel.Row Then
With Range(topCel, bottomCel)
Set c = .Find(whatval, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
Do
c.Cut Destination:=c.Offset(0, -1)
Set c = .FindNext
Loop While Not c Is Nothing
End If
End With
End If
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Compare columns and move data based on a value and change the sign

On Apr 5, 9:32 am, JLGWhiz wrote:
Sub switch()
lstRw = Cells(Rows.Count, 3).End(xlUp).Row
Set myRng = Range("$C$2:$C" & lstRw)
For Each c in myRng
If c 0 Then
cRng = c.Address
Range(cRng).Offset(0, -1) = Range(cRng).Value *v(-1)
Range(cRng) = 0
End If
Next
End Sub

" wrote:
To all the programming Guru's out there.
I'm trying to make some VB code that will look at a column and if the
value in that column is greater than 0,
move it to the corresponding column to the left and change the sign to
a negative.
Below is an example of data I am using.
Column A B C
CASH 125.00 0
CASH2 0 180.00
CASH3 0 12,000.00


So in the rows with cash2 and cash 3 I would like to move those values
to column B and make
them negative.
Below is the code I have that will move data based on an input box but
I have to put the value I want to change in there, and it will not
make the value negative. I would rather have this input box be set to
not equal to what I put in the box, but I'm not sure that an Input box
is designed to do that? Any help would be greatly appreciated.
Thank you


Sub Move_Stuff()
Dim topCel As Range
Dim bottomCel As Range


whatval = InputBox("Enter a Value")


Set topCel = Range("C1")
Set bottomCel = Cells((800), topCel.Column).End(xlUp)
If bottomCel.Row = topCel.Row Then
With Range(topCel, bottomCel)
Set c = .Find(whatval, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
Do
c.Cut Destination:=c.Offset(0, -1)
Set c = .FindNext
Loop While Not c Is Nothing
End If
End With
End If
End Sub


GLJWhiz,
Thank you for the help that worked perfectly for what I was looking
for.
Thank you again!!

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 sign of sum is negative change to positive BigR Excel Worksheet Functions 1 January 12th 10 07:20 PM
Compare 2 colmns based off data in other columns Steve C Excel Discussion (Misc queries) 7 December 13th 07 08:58 AM
change negative sign from end of the number to the begining James Excel Discussion (Misc queries) 11 September 23rd 06 05:36 PM
change the negative sign to brackets but no choice is available the old guy Excel Worksheet Functions 1 March 16th 06 11:17 PM
Deleting a negative sign from an amount in a list (not trailing negative) Fleming Excel Programming 3 May 7th 04 03:50 PM


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