+ Reply to Thread
Results 1 to 3 of 3

Change Positive to Negative

Hybrid View

  1. #1
    Registered User
    Join Date
    08-14-2007
    Posts
    7

    Change Positive to Negative

    Hello, All.

    I am trying to code to change certain numbers from positive to negative and vice versa based upon the value in column A (I have attached a worksheet to illustrate what I am about to describe).

    I have a list of accounts in Column A.
    I have a list of amounts in Column B.

    I am trying to code a macro to look at Column A and perform the following:

    If A = 28XXX then the value in Column B should be a negative value.

    If A = 395XX then the value in Column B should change accordingly (if positive, make negative; if negative, make positive

    Any assistance would be greatly appreciated!

    Thank you in advance.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    Give this a try:
    Sub test()
        Dim iLastRow As Long
        iLastRow = Range("A" & Rows.Count).End(xlUp).Row
        For Each rng In Range("A2:A" & iLastRow)
            If Left(rng.Value, 2) = 28 And rng.Offset(0, 1).Value > 0 Then
                rng.Offset(0, 1) = rng.Offset(0, 1) * -1
            End If
            If Left(rng.Value, 3) = 395 Then
                rng.Offset(0, 1) = rng.Offset(0, 1) * -1
            End If
        Next rng
    End Sub

  3. #3
    Registered User
    Join Date
    08-14-2007
    Posts
    7

    Thank you

    Thank you for your quick response to my question. Everything worked very well!

    Thanks again!

+ 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