figment222
New Member
- Joined
- Mar 6, 2015
- Messages
- 48
I keep getting this error, but only when I'm on a page other than the page of the range object i'm setting.
This line towards the bottom is the one highlighted when the runtime error occurs:
This code works, as long as I have Sheet3 displayed, but not if I am looking at sheet10. I have Option Explicit at the top of the module and I believe I have properly declared all variables. I know the references are ok, because it runs fine, as long as I am on sheet3, but I plan to have this sheet hidden and do not want to have it displayed when this code is run.
any ideas?
Code:
Option Explicit
Public Sub LoadRecord()
Dim Sheet3 As Worksheet
Dim Sheet10 As Worksheet
Dim SettingsCol As Long
Dim FinalCol As Long
Dim QuoteIDVal As Long
Dim GageNumVal As Long
Dim FeatNumVal As Long
Dim RecordRow As Long
Dim SettingsCount As Long
Dim RecordRange As Range
Dim Destination As Range
Set Sheet3 = Worksheets("Records")
Set Sheet10 = Worksheets("Parameters")
'QuoteIDVal = Wizard.ComboBox2.Text
'GageNumVal = Wizard.ComboBox3.Text
'FeatNumVal = Wizard.ComboBox4.Text
QuoteIDVal = 1030001
GageNumVal = 1
FeatNumVal = 1
If MatchRecordRow(QuoteIDVal, GageNumVal, FeatNumVal, "B", "C", "D", "Records") = 0 Then
MsgBox "Record Not Found"
Exit Sub
Else
RecordRow = MatchRecordRow(QuoteIDVal, GageNumVal, FeatNumVal, "B", "C", "D", "Records")
'MsgBox "Record is found in row: " & RecordRow
End If
SettingsCol = Sheet3.Range("1:1").Find("Settings").Column + 1
FinalCol = Sheet3.Range("1:1").Find("Final").Column
Set RecordRange = Sheet3.Range(Cells(RecordRow, SettingsCol), Cells(RecordRow, FinalCol))
SettingsCount = FinalCol - SettingsCol
MsgBox SettingsCount
This line towards the bottom is the one highlighted when the runtime error occurs:
Code:
Set RecordRange = Sheet3.Range(Cells(RecordRow, SettingsCol), Cells(RecordRow, FinalCol))
This code works, as long as I have Sheet3 displayed, but not if I am looking at sheet10. I have Option Explicit at the top of the module and I believe I have properly declared all variables. I know the references are ok, because it runs fine, as long as I am on sheet3, but I plan to have this sheet hidden and do not want to have it displayed when this code is run.
any ideas?