Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Copy cell to first available cell in a named range

Posted on 2011-04-28
Medium Priority
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

SiddharthRout earned 1000 total points
ID: 35489662
Is this what you wanted?


Author Comment

ID: 35490546
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 42

Accepted Solution

dlmille earned 1000 total points
ID: 35493421
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,


Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 42

Expert Comment

ID: 35493429
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 42

Expert Comment

ID: 35843405
@kwat652 - how did the solution work for you?

LVL 24

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

569 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