The '.' always refers back to the previous With statement be it a range,sheet, or other object. So you have to be careful if you're reading and writing to separate objects within only one With statement.
It may be easier to define your objects upfront which will make it easier to handle. Also I would avoid all use of Select and Activate. Your code up to the red could be improved using something like
- Code: Select all
Dim objCurrentWB As Workbook
Dim objWriteWB As Workbook
Dim booObjectsLoaded As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Static MyMarket As Variant
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
If booObjectsLoaded = False Then
'set Objects - In this case a read and write workbooks
Set objCurrentWB = ThisWorkbook
Set objWriteWB = GetObject("C:\Users\osknows\Desktop\Race Upload.xlsm")
'objWriteWB.Parent.Windows(objWriteWB.Name).Visible = True 'set
visible or not
booObjectsLoaded = true
End If
With objCurrentWB
If .Sheets("DataWin").Range("T2").Value <> 1 Then
.Sheets("DataWin").Range("T3").Value = 0
'GoTo Mrkt
End If
If .Sheets("DataWin").Range("T2").Value = 1 And _
.Sheets("DataWin").Range("T3").Value <> 1 Then
objWriteWB.Sheets("Race").Range("I7").Value = .Sheets("Control").Range("AC25").Value
End If
'.
'.
'etc
End With
Application.EnableEvents = True
End Sub