Results 1 to 2 of 2

Thread: VB macro for Excel calculations

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    1

    VB macro for Excel 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
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: VB macro for Excel calculations

    Put the cell address as text in the range A1 through D4 and try this ... you'll see that the base for a cell in a range is (1,1)
    Code:
    Option Explicit
    Sub Macro1()
        Dim aRange As Range
        Set aRange = Range("B2:D4")
        aRange.Select
        MsgBox aRange.Cells(1, 1).Text  'Displays "B2"
    End Sub
    I hope this helps ...
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

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



Click Here to Expand Forum to Full Width