Results 1 to 5 of 5

Creating Stock in and out data forms to take or remove quantities from an inventory sheet

Threaded View

  1. #4
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Creating Stock in and out data forms to take or remove quantities from an inventory sh

    Hi HarrietEllen,

    I changed it to this, wich does exact the same exept the row mistake offcourse

    Sub MoveStockToTable()
    '
    ' MoveStockToTable Macro
    ' Moves
    '
    Dim arr(7) As Variant, rng As Range, cel As Range, I As Long
    ' select input
        Sheets("Stock In").Activate
        Set rng = Range("C4:C9")
        'get data from input
        I = 0
        For Each cel In rng
           arr(I) = cel.Value
           I = I + 1
        Next cel
        
        'Go to Database
        Worksheets("Sheet4").Activate
        'find first empty row after Header row
        I = Worksheets("Sheet4").Columns(1).Find(What:=vbNullString, Lookat:=xlWhole, After:=Worksheets("Sheet4").Range("A3")).Row
        Set rng = Range(Cells(I, 1), Cells(I, 6))
        'put collected data in found open row
        I = 0
        For Each cel In rng
           cel = arr(I)
           I = I + 1
        Next cel
    
    End Sub
    But i made an effort to make it a bit smarter with updating the Stock by searching the ID first and if its in the data just add to the stock

    
    Sub MoveStockToTable()
    '
    ' MoveStockToTable Macro
    ' Moves
    ' checks for existing ID
    Dim arr(7) As Variant, rng As Range, cel As Range, I As Long, DataExists As Boolean
    ' select input
        Sheets("Stock In").Activate
        Set rng = Range("C4:C9")
        'get data from input
        I = 0
        For Each cel In rng
           arr(I) = cel.Value
           I = I + 1
        Next cel
        
        'Go to Database
        Worksheets("Sheet4").Activate
        'If Id already in data just add to stock
        On Error Resume Next
        I = Worksheets("Sheet4").Columns(1).Find(What:=arr(0), Lookat:=xlWhole, After:=Worksheets("Sheet4").Range("A3")).Row
        On Error GoTo 0
        If I = 0 Then
           'find first empty row after Header row
           I = Worksheets("Sheet4").Columns(1).Find(What:=vbNullString, Lookat:=xlWhole, After:=Worksheets("Sheet4").Range("A3")).Row
          Else
           DataExists = True
        End If
        
        If DataExists Then
           'if ID found only update Stock
           Set cel = Range(Cells(I, 6), Cells(I, 6))
           cel.Value = cel.Value + arr(5)
          Else
           Set rng = Range(Cells(I, 1), Cells(I, 6))
           'put collected data in found open row
           I = 0
           For Each cel In rng
              cel = arr(I)
              I = I + 1
           Next cel
        End If
        
    End Sub
    I hope you can use it.

    ps.
    When adding this new code in the same page you might want to change the name of the old macro
    Last edited by Joske920; 10-07-2018 at 03:12 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Looking for help on a Loop to find and update stock sheet quantities
    By kuduck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-15-2015, 05:21 PM
  2. Creating a basic stock inventory sheet
    By 72saints72 in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 07-27-2014, 05:44 AM
  3. I need a stock order sheet to be created from a stock inventory
    By tamhav in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-20-2014, 10:40 AM
  4. Creating User-Friendly Forms for Inventory Entry
    By k64 in forum Excel General
    Replies: 1
    Last Post: 11-12-2013, 02:22 AM
  5. Creating an automatic stock list/inventory, HELP!
    By ibz1000 in forum Excel General
    Replies: 1
    Last Post: 08-01-2013, 05:35 AM
  6. Inventory Stock Balancing with Inventory Data
    By bingbangboom in forum Excel General
    Replies: 2
    Last Post: 01-30-2011, 11:06 PM
  7. Are there any inventory forms that change quantities as needed?
    By Nelson in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-01-2006, 01:15 PM

Tags for this Thread

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