+ Reply to Thread
Results 1 to 4 of 4

Macro to compare cell contents and make calculations

  1. #1
    Registered User
    Join Date
    11-07-2005
    Posts
    4

    Macro to compare cell contents and make calculations

    Hello,

    I'm trying to write a macro that will downcount inventory on an Excel spreadsheet as long as the part number value has not changed.

    My logic is as follows:

    If (Part current) = (Part previous), then Stock (current row) = Stock (previous row) - Qty (previous row)

    I tried to code this in VB as follows:

    If Cells(-1, -3) = Cells(0, -3) Then Cells(0, 6) = Cells(-1, 6) - Cells (-1, 1)

    This doesn't work, and I am not sure why. I have played around with parentheses, added ".Value", and anything else I thought might work. Can anyone help?

    Thanks in advance.

  2. #2
    Rowan Drummond
    Guest

    Re: Macro to compare cell contents and make calculations

    Maybe like this:

    With ActiveCell
    If .Offset(-1, -3) = .Offset(0, -3) Then _
    .Offset(0, 6) = .Offset(-1, 6) - .Offset(-1, 1)
    End With

    Hope this helps
    Rowan

    Stereolab wrote:
    > Hello,
    >
    > I'm trying to write a macro that will downcount inventory on an Excel
    > spreadsheet as long as the part number value has not changed.
    >
    > My logic is as follows:
    >
    > If (Part current) = (Part previous), then Stock (current row) = Stock
    > (previous row) - Qty (previous row)
    >
    > I tried to code this in VB as follows:
    >
    > If Cells(-1, -3) = Cells(0, -3) Then Cells(0, 6) = Cells(-1, 6) - Cells
    > (-1, 1)
    >
    > This doesn't work, and I am not sure why. I have played around with
    > parentheses, added ".Value", and anything else I thought might work.
    > Can anyone help?
    >
    > Thanks in advance.
    >
    >


  3. #3
    Registered User
    Join Date
    11-07-2005
    Posts
    4
    Rowan,

    THANK YOU.

    You are my hero.

  4. #4
    Rowan Drummond
    Guest

    Re: Macro to compare cell contents and make calculations

    You're welcome.

    Stereolab wrote:
    > Rowan,
    >
    > THANK YOU.
    >
    > You are my hero.
    >
    >


+ 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