+ Reply to Thread
Results 1 to 4 of 4

Move Negative Number and Change to a Positive Number

Hybrid View

Alvin Hunter Move Negative Number and... 02-02-2013, 06:37 PM
Alvin Hunter Re: Move Negative Number and... 02-03-2013, 12:19 PM
jeffreybrown Re: Move Negative Number and... 02-03-2013, 12:44 PM
Alvin Hunter Re: Move Negative Number and... 02-04-2013, 08:36 PM
  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    26

    Move Negative Number and Change to a Positive Number

    Hello All,

    I am looking for a vba to attach to an existing vba. Please see text below highlighted in red.

    Thanks in advance,

    Alvin

    If Application.WorksheetFunction.CountA("K:K") = 0 Then
     [K1].Select
     Else
     On Error Resume Next
     Columns(11).SpecialCells(xlCellTypeBlanks)(1, 1).Select
     If Err <> 0 Then
     On Error GoTo 0
     [K65536].End(xlUp)(2, 1).Select
     End If
     On Error GoTo 0
     End If
     Selection.FillDown

    The FillDown will bring a formula, from the cell above it and will show a resulting number.

    Here is what I would like the vba to do next...

    If the resulting number from the FillDown is negative, then cut and paste values one cell to the left as a positive number. If number is positive then do nothing.
    Last edited by jeffreybrown; 02-03-2013 at 12:45 PM.

  2. #2
    Registered User
    Join Date
    12-22-2011
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Move Negative Number and Change to a Positive Number

    Well, I figured it out, Yeah! I researched every step along with trial and error. But, I'm still getting better at this the more I do it. Fun!


    If ActiveCell.Value < 0 Then
    ActiveCell.copy
    
    ActiveCell.Offset(0, -1).Activate 'means same row and one col left
    Selection.PasteSpecial paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
    ActiveCell.copy
    
    End If
    
    ActiveCell.Offset(0, 1).Activate 'means same row and one col right
    Selection.ClearContents
    
    Dim cel As Range
    For Each cel In Columns("J").SpecialCells(xlCellTypeConstants, 1)  'changes negative numbers to positive numbers in the entire column
        cel.Value = Abs(cel)
    Next
    
    Range("D1").Select
    Selection.ClearContents
    Last edited by Alvin Hunter; 02-04-2013 at 08:35 PM.

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Move Negative Number and Change to a Positive Number

    @Alvin,

    Glad to hear you figured out your solution...

    Administrative Note:
    • Please see Forum Rule #3 about code tags and adjust accordingly...
    • Added for you this time, but please use them in the future…Thanks.

    Also, this may be of some help to you when writing macros...

    Beyond Excel’s Macro Recorder
    Last edited by jeffreybrown; 02-03-2013 at 12:46 PM.
    HTH
    Regards, Jeff

  4. #4
    Registered User
    Join Date
    12-22-2011
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Move Negative Number and Change to a Positive Number

    Thank you Jeffrey

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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