Warship
Well-known Member
- Joined
- Jul 17, 2007
- Messages
- 1,055
- Office Version
- 2016
- 2013
- 2007
- Platform
- Windows
I finally got this macro to run, or so I thought. When I run it manually all is well. However when I run it from workbook_open only the bottom two offsets actually set their values, the top three remain empty.
Sub LoadProtusMateData()
Application.ScreenUpdating = False
'CLEARCONTENTS OF TARGET CELLS
Sheets("MAIN").Select
Range("UserInput").ClearContents 'cols D,E,F
Range("BrokenTimes").ClearContents 'col AV
Range("StartCheck").ClearContents 'col AI
'RETRIEVE DATA
Application.Calculation = xlManual
Sheets("MAIN").Unprotect
For Each num In Range("UnitNum")
With Worksheets("ProtusMateData").Range("ProtusMateDataUnitNum")
Set x = .Find(num.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not x Is Nothing Then
num.Offset(0, -3).Value = x.Offset(0, 1).Value 'col D
num.Offset(0, -2).Value = x.Offset(0, 2).Value 'col E
num.Offset(0, -1).Value = x.Offset(0, 3).Value 'col F
num.Offset(0, 28).Value = x.Offset(0, 4).Value 'col AI
num.Offset(0, 41).Value = x.Offset(0, 5).Value 'col AV
End If
End With
Next num
Range("UnitCountConstant") = Range("UnitCountProtusData") 'updates to new unit count
Application.Calculation = xlAutomatic
ProtectMain
End Sub
I have tried everything to isolate the problem such as running ONLY this code from workbook_start, same result.
I even tried offsetting to different cols then copy and paste from there to proper cols and it won't copy and paste to cols D-F either.
I tried removing all protection.
I tried moving Range("UnitNum") to col B to avoid negative offsets.
I tried removing all conditional formatting.
There is never an error and again, when ran manually it always works fine.
I'm guessing there is something with cols D, E and F. What else it could be I can't figure.
What's baffling is it runs manually just fine!
I am tried out....Please help!
Thanks in advance for any help and suggestions
Sub LoadProtusMateData()
Application.ScreenUpdating = False
'CLEARCONTENTS OF TARGET CELLS
Sheets("MAIN").Select
Range("UserInput").ClearContents 'cols D,E,F
Range("BrokenTimes").ClearContents 'col AV
Range("StartCheck").ClearContents 'col AI
'RETRIEVE DATA
Application.Calculation = xlManual
Sheets("MAIN").Unprotect
For Each num In Range("UnitNum")
With Worksheets("ProtusMateData").Range("ProtusMateDataUnitNum")
Set x = .Find(num.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not x Is Nothing Then
num.Offset(0, -3).Value = x.Offset(0, 1).Value 'col D
num.Offset(0, -2).Value = x.Offset(0, 2).Value 'col E
num.Offset(0, -1).Value = x.Offset(0, 3).Value 'col F
num.Offset(0, 28).Value = x.Offset(0, 4).Value 'col AI
num.Offset(0, 41).Value = x.Offset(0, 5).Value 'col AV
End If
End With
Next num
Range("UnitCountConstant") = Range("UnitCountProtusData") 'updates to new unit count
Application.Calculation = xlAutomatic
ProtectMain
End Sub
I have tried everything to isolate the problem such as running ONLY this code from workbook_start, same result.
I even tried offsetting to different cols then copy and paste from there to proper cols and it won't copy and paste to cols D-F either.
I tried removing all protection.
I tried moving Range("UnitNum") to col B to avoid negative offsets.
I tried removing all conditional formatting.
There is never an error and again, when ran manually it always works fine.
I'm guessing there is something with cols D, E and F. What else it could be I can't figure.
What's baffling is it runs manually just fine!
I am tried out....Please help!
Thanks in advance for any help and suggestions