Consulting

Results 1 to 2 of 2

Thread: Can't get my code to offset

  1. #1
    VBAX Regular
    Joined
    Mar 2014
    Posts
    18
    Location

    Can't get my code to offset

    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. It's driving me crazy. Thank You

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •