+ Reply to Thread
Results 1 to 2 of 2

Row, Col value off by one row

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2008
    Posts
    74

    Row, Col value off by one row

    I don't know what has happened here. The value I am getting from the target row col is off by one row even though the row count is correct.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       
    Dim strContNam As String
    Dim intClassNum As Integer
    Dim intLastRow As Integer
    Dim aryClasses As Variant
    Dim intCount As Integer
    
    'First find out if this is an addition, or a read.
    If frmEntry.lblField.Caption = "Writing" Then Exit Sub
    
    'Get the last row
    intLastRow = FindLastRow
    
    'Check which row was selected.  It must be greater than 1 and less than last row
        If Target.Row > 1 And Target.Row < intLastRow Then
            With frmEntry
                .txtNumber.Value = Target.Cells(Target.Row, Range("ContestantNumber").Column).Value
                .txtName.Value = Target.Cells(Target.Row, Range("ContestantName").Column).Value
                .cboAgeGroup = Target.Cells(Target.Row, Range("Group").Column).Value
    When I step through this the Row value is 2, the column value is 1 the data in that cell should be 123 but it is the value from the next row.
    Scott
    The harder it gets the happier I am.
    Finally got my signature set up!

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    The way you have your code written, it is using target as the starting point, then using CELLS to work out where to go. As the row number for TARGET, the effect is to go 2 rows from target, then across the required number of columns. If TARGET was in row 3, then you would be 3 rows off.

    Try something like
    cells(target.row,Range("ContestantNumber").Column).value
    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1