PC Review


Reply
Thread Tools Rate Thread

Compare columns and move data based on a value and change the sign to negative

 
 
banderson@nwws.biz
Guest
Posts: n/a
 
      5th Apr 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      5th Apr 2007
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


"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      5th Apr 2007
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
>
>
> "(E-Mail Removed)" 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
> >
> >

 
Reply With Quote
 
banderson@nwws.biz
Guest
Posts: n/a
 
      5th Apr 2007
On Apr 5, 9:32 am, JLGWhiz <JLGW...@discussions.microsoft.com> 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
>
> "bander...@nwws.biz" 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If sign of sum is negative change to positive BigR Microsoft Excel Worksheet Functions 1 12th Jan 2010 07:20 PM
Compare 2 colmns based off data in other columns Steve C Microsoft Excel Misc 7 13th Dec 2007 08:58 AM
change negative sign from end of the number to the begining =?Utf-8?B?amFtZXM=?= Microsoft Excel Misc 11 23rd Sep 2006 05:36 PM
change the negative sign to brackets but no choice is available =?Utf-8?B?dGhlIG9sZCBndXk=?= Microsoft Excel Worksheet Functions 1 16th Mar 2006 11:17 PM
Reversing Sign on Column of Data (Positive to Negative) (Negative to Postive) M Stokes Microsoft Excel Worksheet Functions 1 26th Apr 2004 04:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:34 PM.