+ Reply to Thread
Results 1 to 8 of 8

Reversing the signs of selected cells - help neededddd

Hybrid View

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    3

    Reversing the signs of selected cells - help neededddd

    Hi,

    I need a VBA macro code for the below mentioned problem:-

    Suppose I have the following data in multiple cells, not nessecarily one after the another.

    34 in Cell C6


    12 in Cell C10


    12 in Cell C12


    What I want is the following output by clicking a button (macro inside it) in the same cells and paste them as values


    -34


    -12


    -12


    Can anyone of you brilliant minds help me out.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: Reversing the signs of selected cells - help neededddd

    You don't need a macro. Put -1 in an empty cell somewhere (e.g. cell E1). Select the cell with the -1 in and click copy. Then click on cell C6, hold down the CTRL key and click on cell C10, then hold the CTRL key again and click on cell C12. Then right-click and choose Paste Special, and click against Values and against Multiply, then click OK and press the <Esc> key. Then you can remove the -1 from the first cell.

    If you really need a macro then turn the Macro Recorder on and complete the above steps.

    Hope this helps.

    Pete

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Reversing the signs of selected cells - help neededddd

    Select the cell(s) then run the code
    Sub test()
        Dim r As Range
        For Each r In Selection
            r.Value = Val(r.Value) * -1
        Next
    End Sub

  4. #4
    Registered User
    Join Date
    08-06-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Reversing the signs of selected cells - help neededddd

    @Jindon Like your code man. Thanks.! But can I mention the cells in the code instead of selecting it and running the macro. Please help me with the syntax :-(

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Reversing the signs of selected cells - help neededddd

    Sub chagneme()

    With ActiveSheet
        For Each cel In .Range("C1", .Range("C" & .Rows.Count).End(xlUp))
            If Len(cel) Then
                cel.Value = Val(cel.Value) * -1
            End If
        Next
    End With
    End Sub
    Last edited by AB33; 08-12-2013 at 11:00 AM.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Reversing the signs of selected cells - help neededddd

    Change Selection to something like

    For Each r In Range("C6,C10,C12")

  7. #7
    Registered User
    Join Date
    08-06-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Reversing the signs of selected cells - help neededddd

    @Jindon. great buddy. thanks. one more thing - if I want to have my range defined in format "Cells(rowNo, colNo)", how will the syntax look like?? See my code below, in this case my colno I know. row no, i can change.. but how it will look like in syntax - For Each r In Range("C6,C10,C12") ???

    Suppose I have a code like this -

    Dim Datev As String

    Datev = Sheets("hello").Cells(1, 10).Value
    Datev = Mid(Datev, 4, 2)
    'MsgBox (Datev)

    colNo = 3
    Do While Sheets("hello").Cells(11, colNo).Value <> Datev
    colNo = colNo + 1
    Loop

    Dim r As Range
    For Each r In Range("C6,C10,C12")
    r.Value = Val(r.Value) * -1
    Next

    End Sub
    Last edited by er.twi.fb; 08-12-2013 at 11:13 AM.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Reversing the signs of selected cells - help neededddd

    1) You must edit your last post and wrap the code with the code tag.
    [code]
    VBA Code here
    [/code]


    No idea.

    Just a guess
    Do While Sheets("hello").Cells(11, colNo).Value <> Datev
        Sheets("hello").Cells(11, colNo).Value = Sheets("hello").Cells(11, colNo).Value * -1
    colNo = colNo + 1
    Loop

+ 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. concatenation of cells including citation signs
    By olef4 in forum Excel General
    Replies: 2
    Last Post: 05-02-2011, 09:16 AM
  2. Code which deletes all signs behind a number of signs
    By Mula in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-30-2009, 05:53 AM
  3. How to get rid of $ signs in cells?
    By Andyc7 in forum Excel General
    Replies: 8
    Last Post: 09-02-2007, 12:29 PM
  4. Reversing Cells
    By Warrior01 in forum Excel General
    Replies: 1
    Last Post: 05-14-2007, 01:29 AM
  5. Reversing characters of cells
    By starguy in forum Excel General
    Replies: 12
    Last Post: 06-13-2006, 01:00 PM

Tags for this Thread

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