PDA

View Full Version : Can't get my code to offset



jcutler
08-26-2018, 01:52 PM
Sub Test()

Dim ws_count As Integer, i As Integer, FinalRow As Integer, x As Integer

ws_count = ActiveWorkbook.Worksheets.Count
For i = 4 To ws_count
Worksheets(i).Activate
FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
For x = 1 To FinalRow
If Cells(x, 2) & " " & "(" & Cells(x, 3) & ")" = Chattemfrm.cmbPrdCde.Value Then
'Cells(x, 2).Select
txtDz = Cells(x, 2).Offset(0, 2).Value
txtCs = Cells(x, 2).Offset(0, 3).Value
txtUOM = Cells(x, 2).Offset(0, 4).Value
Cells(x, 2).Interior.ColorIndex = 3
End If
Cells(x, 2).Select
Next x
Next i
End Sub

txtDz = Cells(x, 2).Offset(0, 2).Value
txtCs = Cells(x, 2).Offset(0, 3).Value
txtUOM = Cells(x, 2).Offset(0, 4).Value
For whatever reason it won't offset when I step through it.:banghead::crying: It's driving me crazy. Thank You

offthelip
08-26-2018, 03:07 PM
I would never use offset in those conditions anyway since the offset is not "calculated" you can address the cells directly:


txtDz = Cells(x, 4).Value
txtCs = Cells(x, 5).Value
txtUOM = Cells(x, 6).Value