• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Copy cell to first available cell in a named range

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
0
kwatt562
Asked:
kwatt562
2 Solutions
 
SiddharthRoutCommented:
Is this what you wanted?

Sid
trials1.xlsm
0
 
kwatt562Author Commented:
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.
0
 
dlmilleCommented:
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

    Sheets("Jobtimes").Range("A3").Copy
    
    'Find last blank cell in named range
    
    Sheets("Timeline").Select

    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
                    myCell.Select
                        'Paste WO to last blank cell in named range
            
                    ActiveSheet.Paste
                    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,

Enjoy!

Dave
trials1-r2.xlsm
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
dlmilleCommented:
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.

Dave
0
 
dlmilleCommented:
@kwat652 - how did the solution work for you?

Dave
0
 
TracyVBA DeveloperCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now