+ Reply to Thread
Results 1 to 6 of 6

Stock adjustment Data in excel

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2012
    Location
    chennai
    MS-Off Ver
    Excel 2019
    Posts
    55

    Stock adjustment Data in excel

    Hi

    I have 3 following datas in the columns
    1) Opening Balance
    2) Product Sold
    3) Closing Balance (Difference between Opening balance - Products Sold)

    In the attached excel sheet some of the closing balance is showing as negative (Minus).

    If the Closing balance is less than zero like (-1,-2,-3 etc) then the Product sold column to be changed like decrease 1 number (-1) till the closing balance come to zero.
    For example in the first case the Product Name apple Opening balance is 100 and unit sold is 105. The closing balance is showing as -5
    Now the units sold be changed to 100. Now i doing manually till the closing balance get zero.
    This should do only if the closing balance is negative balance.
    I need this in macro because i have many of products using loop based on the available data in the sheet.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,280

    Re: Stock adjustment Data in excel

    Try:
    Sub AAA()
        Dim vData       As Variant
        Dim i           As Long
    
        With ActiveSheet.Range("A1").CurrentRegion
            With .Offset(1).Resize(.Rows.Count - 1).Columns("B:C").Cells
                vData = .Value
    
                For i = 1 To UBound(vData)
                    If vData(i, 2) > vData(i, 1) Then
                        vData(i, 2) = vData(i, 1)
                    End If
                Next i
    
                .Value = vData
            End With
        End With
    
    End Sub
    Artik

  3. #3
    Registered User
    Join Date
    07-08-2012
    Location
    chennai
    MS-Off Ver
    Excel 2019
    Posts
    55

    Re: Stock adjustment Data in excel

    Thanks working

    can you explain about this line

    vData = .Value

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,280

    Re: Stock adjustment Data in excel

    ActiveSheet.Range("A1").CurrentRegion is the range A1:D5.
    .Offset(1).Resize(.Rows.Count - 1).Columns("B:C").Cells is the range A1:D5 shifted down one row and minus one row, so you get the range A2:D5. And in this area, we are interested in the data from columns B:C.
    vData = .Value is to get the data from the range B2:C5 to the vData variable.

    Artik

  5. #5
    Registered User
    Join Date
    07-08-2012
    Location
    chennai
    MS-Off Ver
    Excel 2019
    Posts
    55

    Re: Stock adjustment Data in excel

    Thanks for the clarification.
    I need additional one column in the E Column. The difference value to be shown in the E column (Next to Closing Balance)

    For example in the first case the Product Name apple Opening balance is 100 and unit sold is 105. The closing balance is showing as -5
    The same Difference value 5 to be shown in the E2 Column.

  6. #6
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,280

    Re: Stock adjustment Data in excel

    Sub BBB()
        Dim vData       As Variant
        Dim vResultE As Variant
        Dim i           As Long
    
        With ActiveSheet.Range("A1").CurrentRegion
            With .Offset(1).Resize(.Rows.Count - 1).Columns("B:C").Cells
                vData = .Value
                
                ReDim vResultE(1 To UBound(vData), 1 To 1)
    
                For i = 1 To UBound(vData)
                    vResultE(i, 1) = vData(i, 2) - vData(i, 1)
                    
                    If vData(i, 2) > vData(i, 1) Then
                        vData(i, 2) = vData(i, 1)
                    End If
                Next i
    
                .Value = vData
                .Offset(, 3).Resize(, 1).Value = vResultE
            End With
        End With
    
    End Sub
    Artik

+ 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. Replies: 1
    Last Post: 04-15-2020, 03:40 PM
  2. Replies: 31
    Last Post: 10-28-2015, 01:54 AM
  3. Replies: 0
    Last Post: 04-10-2015, 04:34 PM
  4. VBA Code to pull Stock Balance Sheet Data from a Stock Symbol in a cell
    By akash1229 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-27-2015, 04:37 PM
  5. Replies: 0
    Last Post: 10-28-2012, 07:22 AM
  6. Merge and add rows/values and stock adjustment
    By OJP1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2010, 05:10 AM
  7. [SOLVED] How can I use Dutch (NL) stock MSN MoneyCentral Stock in Excel
    By Jeroen in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-16-2006, 11:20 AM

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