+ Reply to Thread
Results 1 to 4 of 4

Change cell to negative Value

Hybrid View

  1. #1
    Registered User
    Join Date
    08-04-2014
    Location
    Stockholm
    MS-Off Ver
    2013
    Posts
    58

    Change cell to negative Value

    Hello,

    I use the below code to change the cell value from positive to negative.
    You click the cells you wanna change to negative.

    However, I want to adjust it so that if I click on a cell between columns N to W
    I want it to change the cells on the same row in column Q and R, not the actual cell you click.

    Is this possible?

       End If
    
         
        
        End Sub
        
        Sub ChangeToNegative()
        
        Dim rng As Range
        Dim WorkRng As Range
        On Error Resume Next
        xTitleId = "Kalkyl"
        
        Set WorkRng = Application.Selection
        Set WorkRng = Application.InputBox("Markera de celler du vill retunera/ta bort:", xTitleId, WorkRng.Address, Type:=8)
        Set WorkRng = WorkRng.SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each rng In WorkRng
        xValue = rng.Value
        If xValue > 0 Then
        rng.Value = xValue * -1
        
        End If
        Next
        
        End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Change cell to negative Value

    Maybe?

    Sub cajand()
        Dim rng As Range
        Dim WorkRng As Range
        On Error Resume Next
        xTitleId = "Kalkyl"
        
        Set WorkRng = Application.Selection
        Set WorkRng = Application.InputBox("Markera de celler du vill retunera/ta bort:", xTitleId, WorkRng.Address, Type:=8)
        Set WorkRng = WorkRng.SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each rng In WorkRng
        If rng.Column > 13 And rng.Column < 24 Then
        xValue = Cells(rng.Row, "Q").Value
        If xValue > 0 Then
        Cells(rng.Row, "Q").Value = xValue * -1
        End If
        yValue = Cells(rng.Row, "R").Value
        If yValue > 0 Then
        Cells(rng.Row, "R").Value = yValue * -1
        End If
        End If
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    08-04-2014
    Location
    Stockholm
    MS-Off Ver
    2013
    Posts
    58

    Re: Change cell to negative Value

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe?

    Sub cajand()
        Dim rng As Range
        Dim WorkRng As Range
        On Error Resume Next
        xTitleId = "Kalkyl"
        
        Set WorkRng = Application.Selection
        Set WorkRng = Application.InputBox("Markera de celler du vill retunera/ta bort:", xTitleId, WorkRng.Address, Type:=8)
        Set WorkRng = WorkRng.SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each rng In WorkRng
        If rng.Column > 13 And rng.Column < 24 Then
        xValue = Cells(rng.Row, "Q").Value
        If xValue > 0 Then
        Cells(rng.Row, "Q").Value = xValue * -1
        End If
        yValue = Cells(rng.Row, "R").Value
        If yValue > 0 Then
        Cells(rng.Row, "R").Value = yValue * -1
        End If
        End If
        Next
    End Sub
    This works perfectly! Thank you!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Change cell to negative Value

    You're welcome. Glad to help out and thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Automatically change a value in a cell to negative
    By lheyanne in forum Excel General
    Replies: 4
    Last Post: 12-24-2013, 01:03 AM
  2. Replies: 5
    Last Post: 12-12-2013, 10:35 PM
  3. Replies: 1
    Last Post: 05-09-2013, 08:11 PM
  4. trying to change a cells value to negative based on another cell input
    By cjwanat in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-08-2010, 04:37 PM
  5. change cell from negative to positive
    By Terry in forum Excel General
    Replies: 1
    Last Post: 07-15-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1