Copy cell to first available cell in a named range

Posted on 2011-04-28
Last Modified: 2012-06-27
Hi, I posted this sheet on this site already and someone provided assistance, so hopefully someone can help resolve my latest issue with the excel project from hell. I attach the file, you only need to view the sheets tabbed in red. Basically on Jobtime, you click the button opposite and it creates a schedule of work on the sheet timeline.
First step for the order is handling, then its threaded, then swedged then phosphated. When I click the first button everything works perfect, the WO number is transferred to the appropraite machines, for the appropriate period of time, using last row, offsets and numpastes. The problem occurs when i press the next button which adds in the second order. I attached a sccreenshot to highlight the issue,but basically the code is not finding the first blank cell in my ranges but instead the first blank in a row in my ranges (after offsets)

I have been trying to resolve for days, if anyone solves I will be very happy, but also hate you ;) trials1.xlsm Wrong cell found picture
Question by:kwatt562
    LVL 30

    Assisted Solution

    Is this what you wanted?


    Author Comment

    Hi, It works for that example, but the problem with setting a static offset to move down the column, is that it doesnt allow for any change. Ultimately process 1 (handling) must finish before process 2 (threading) starts, process 2 must finish before process 3 (swedging) starts etc In the last two processes, there are multiple machines available and so the macro needs to move the order to the first available machine (and not queue everything in one machine (row)

    Taking swedging as example, one way I thought of was to create three separate name ranges (1 for each machine) and have the macro pick the first available range, but Im not sure how to code it.
    LVL 41

    Accepted Solution

    Your code should be more something like this.  I only did it for the SWEDGE machine, but you may have other cases where you need to apply the same logic.

    In a multiple machine case, what I'm sensing is that you're looking for a machine (row) that has available time at the OFFSET which I take to mean "time".  I see you're working optimization logic and I'm not going to guess at your mental algorithm and attempt that.

    However, if the machine IS available at that TIME (re: OFFSET), then the SWEDGE machine will be used, otherwise not.

    Here's the code.  Note the enumeration of cells by ROW in the range Rng.  If the first cell CELLS(1,1) is blank, then its availabe, so attempt to load up the machine with the next steps you already had:
    Sub Swedge508()
    Dim LastColumn As Long
    Dim myCell As Range
    Dim Rng As Range
    Dim foundBlanks As Long
    Dim numPastes As Long
    Dim myRow As Range
    'Copy WO to Machine Selector
        'Find last blank cell in named range
        Set Rng = Range("Swedge")
           myvar = Sheets("Jobtimes").Range("E3").Value
    Set Rng = Rng.offset(0, myvar)
        numPastes = Sheets("Jobtimes").Range("F3")
        foundBlanks = 0
        For Each myRow In Rng.Rows 'find a machine with available time, first
            If myRow.Cells(1, 1).Value = "" Then
                For Each myCell In Range(myRow.Address)
                    If myCell.Value = "" And foundBlanks < numPastes Then
                            'Paste WO to last blank cell in named range
                        With Selection.Interior
                            .Pattern = xlSolid
                            .PatternColorIndex = xlAutomatic
                            .ThemeColor = xlThemeColorAccent3
                            .TintAndShade = 0.399975585192419
                            .PatternTintAndShade = 0
                        End With
                        foundBlanks = foundBlanks + 1
                    End If
                Next myCell
            End If
        Next myRow
        If foundBlanks <> numPastes Then
            MsgBox "Machine is Full Today - Could only paste " & foundBlanks, vbOKOnly, "Machine is Full!"
        End If
    End Sub

    Open in new window

    Here's a picture of the output - note SWEDGE machine is now loaded properly:

    Swedge machine loaded "properly"
    See attached,


    LVL 41

    Expert Comment

    Note - as an aside, your assignment of rng = OFFSET is flawed as it goes past available 24 hour cycle.  You'll want to compress the right side of that resulting range, before you move on.

    LVL 41

    Expert Comment

    @kwat652 - how did the solution work for you?

    LVL 24

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Excel add date to text 3 32
    Complex Lookup Formulas 3 30
    VBA filters 2 24
    Excel VBA - make text upside down in a Shape 2 23
    What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
    Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now