The following code takes values from a userform and puts them in the required place of the required worksheet.
Sub EnterIn(Name, w_C, Mac, Meters, hours, jobs, cols, washes)
Dim ws As Worksheet
Select Case Mac
Case "MA1"
Set ws = Sheets("MARKANDYS1")
McRow = 0
Manrow = 9
Case "MA2"
Set ws = Sheets("Markandys2")
McRow = 0
Manrow = 9
Case "SR1"
Set ws = Sheets("SLITTERS1")
McRow = 0
Manrow = 9
Case "OMEGA"
Set ws = Sheets("SLITTERS1")
McRow = 26
Manrow = 25
Case "410"
Set ws = Sheets("SLITTERS2")
McRow = 0
Manrow = 9
Case "OPAL 2"
Set ws = Sheets("SLITTERS2")
McRow = 26
Manrow = 25
Case "ROTOFLEX"
Set ws = Sheets("SLITTERS2")
McRow = 52
Manrow = 61
Case Else
MsgBox ("You must Enter a Machine")
Exit Sub
End Select
If ws.Name = "MARKANDYS1" Or ws.Name = "MARKANDYS2" Then
ReDim enterAr(4) As Variant
enterAr(0) = Meters
enterAr(1) = hours
enterAr(2) = jobs
enterAr(3) = cols
enterAr(4) = washes
End If
If ws.Name = "SLITTERS1" Or ws.Name = "SLITTERS2" Then
ReDim enterAr(2) As Variant
enterAr(0) = Meters
enterAr(1) = hours
enterAr(2) = jobs
End If
With ws
r = Application.WorksheetFunction.Match(Name, .Range(Cells(10 + McRow, 4), Cells(30 + McRow, 4)), 0)
c = Application.WorksheetFunction.Match(w_C, .Range("G9:BF9"), 0)
Dim Destination As Range
Set Destination = ws.Cells(r + Manrow, c + 6)
Set Destination = Destination.Resize(UBound(enterAr) + 1, 1)
Destination.Value = Application.Transpose(enterAr)
.Range(.Cells(r + ManRow, c + 6), .Cells(r + 5 + ManRow, c + 6)).Value = enterAr
End With
End Sub
When this is triggered (by a button on the user form ), if it is directly after opening the application this fails with a error message "Method Range of object __Worksheet failed"
If I then restart the application by clicking Run when the userform code is showing it runs as required with the data put in the correct place.
I need some help to understand what is going wrong.
John
Bookmarks