Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If sign of sum is negative change to positive | Excel Worksheet Functions | |||
Compare 2 colmns based off data in other columns | Excel Discussion (Misc queries) | |||
change negative sign from end of the number to the begining | Excel Discussion (Misc queries) | |||
change the negative sign to brackets but no choice is available | Excel Worksheet Functions | |||
Deleting a negative sign from an amount in a list (not trailing negative) | Excel Programming |