+ Reply to Thread
Results 1 to 9 of 9

order inventory macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-17-2013
    Location
    scotland
    MS-Off Ver
    Excel 2010
    Posts
    6

    order inventory macro

    Hi there
    i have a workbook to track my order process status
    it has 6 pages:
    Stock - New Orders
    CNC
    Make
    Paint
    Dispatch
    Complete
    Every order passes from each sheet in order till complete where it stays

    each row in the sheet has the details of the order
    what i need is to be able to move an order(row) from 1 sheet to the next
    by typing the next stage(which is the next sheets name in column b of the order row

    so an order starts in stock - new orders
    when "cnc" or "make" is inserted into column b of the orders row the order moves to the cnc or make sheet
    then when the same colum b cell is changed to "paint" it moves to the paint sheet and so on

    i tried recording a macro using advanced filter but doesnt move the order only copies it and before long leaves the stock - new orders littered with orders which i cant remove as they dissapear from the other sheets too if i delete them

    Many thanks in advance
    blair

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: order inventory macro

    This macro would go in the ThisWorkbook module and will watch for changes in column B of all sheets. If you change something, it will move it.

    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim cell As Range, wsNm As String
    
    For Each cell In Target
        If cell.Column = 2 And cell.Value <> Sh.Name And cell.Value <> "" Then
            wsNm = cell.Value
            If Evaluate("ISREF('" & wsNm & "'!A1)") Then
                Application.EnableEvents = False
                cell.EntireRow.Cut Sheets(wsNm).Range("A" & Rows.Count).End(xlUp).Offset(1)
                Rows(cell.Row).Delete xlShiftUp
                Sheets(wsNm).Activate               'this is optional to follow the row...delete if not undesired
                Sheets(wsNm).Columns.AutoFit
                Application.EnableEvents = True
            Else
                MsgBox "No sheet with that name exists, row not moved."
            End If
        End If
    Next cell
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-17-2013
    Location
    scotland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: order inventory macro

    HI AGAIN

    AH So Close
    it is working a treat apart from
    the rows once edited with the new status such as make or paint etc over rights the first row in the named sheet ?
    the named sheets only store 1 row and continously gets over written by the next ?

    many thanks
    blair

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: order inventory macro

    Which column in your workbook ALWAYS has data in it on used rows? All my workbooks use column A, but apparently yours are empty.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: order inventory macro

    Hi blairw,

    Why don't you upload a sample WorkBook with all your data, for us to have a look at?
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: order inventory macro

    Since we know column B is being used, perhaps this will work better for you:
                cell.EntireRow.Cut Sheets(wsNm).Range("B" & Rows.Count).End(xlUp).Offset(1, -1)

  7. #7
    Registered User
    Join Date
    03-17-2013
    Location
    scotland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: order inventory macro

    Hi Folks
    i found what the problem was. as i require the cell text auto complete for the various options and items in the same column listed above i had a space inserted in the cells.
    however :
    the script below works very well but when i change the cell in column A and the row goes to the sheet with that name it leaves an empty row
    which interfears with the cell text auto complete. is it possible for the code to remove the row it leaves behind when it moves ?
    much appreciated
    blair

    order inventory.xlsm
    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim cell As Range, wsNm As String
    
    For Each cell In Target
        If cell.Column = 1 And cell.Value <> Sh.Name And cell.Value <> "" Then
            wsNm = cell.Value
            If Evaluate("ISREF('" & wsNm & "'!A1)") Then
                Application.EnableEvents = False
                cell.EntireRow.Cut Sheets(wsNm).Range("A" & Rows.Count).End(xlUp).Offset(1)
                Rows(cell.Row).Delete xlShiftUp
                Sheets(wsNm).Activate               'this is optional to follow the row...delete if not undesired
                Sheets(wsNm).Columns.AutoFit
                Application.EnableEvents = True
            Else
                MsgBox "No sheet with that name exists, row not moved."
            End If
        End If
    Next cell
    
    End Sub
    Last edited by JBeaucaire; 03-18-2013 at 03:23 PM. Reason: Added code tags, as per forum rules. Don't forget!

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: order inventory macro

    Change this:
                cell.EntireRow.Copy Sheets(wsNm).Range("A" & Rows.Count).End(xlUp).Offset(1)

  9. #9
    Registered User
    Join Date
    03-17-2013
    Location
    scotland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: order inventory macro

    DONE !!!
    Thanks JB
    you have put an end to my stressing !!
    i cant thank you enough you have been a great help
    Blair

+ 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