Consulting

Results 1 to 4 of 4

Thread: help please ASAP type mismatch error

  1. #1
    VBAX Newbie
    Joined
    Jun 2013
    Posts
    1
    Location

    Angry help please ASAP type mismatch error

    [VBA]Sub C_how_many_to_insert()
    Sheets("Copied sorted values").Select
    Range("B2").Select
    Do Until ActiveCell.Offset(1, 0).Value = "x"

    ms1 = ActiveCell.Offset(0, 1)
    ms2 = ActiveCell.Offset(1, 1)

    If ms2 - ms1 > 1 Then
    ActiveCell.Value = (ms2 - ms1) - 1
    ActiveCell.Offset(1, 0).Select
    Else: ActiveCell.Offset(1, 0).Select
    End If
    Loop

    Range("B2").Select
    Do Until ActiveCell.Value = "x"
    p1 = ActiveCell.Offset(0, 2)
    p2 = ActiveCell.Offset(1, 2)

    If p1 <> p2 Then
    ActiveCell = 13 - ActiveCell.Offset(0, 1)
    ActiveCell.Offset(1, 0).Select
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Loop

    Range("D2").Select
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(-1, -3).Select
    Do
    p1 = ActiveCell.Offset(0, 3)
    p2 = ActiveCell.Offset(-1, 3)
    m1 = ActiveCell.Offset(0, 2)
    If p1 <> p2 And m1 <> 1 Then
    ActiveCell = (m1 - 1)
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop Until (ActiveCell.Address = "$A$1")

    Cells.Select
    Cells.EntireColumn.AutoFit

    Range("A2").Select
    End Sub[/VBA]


    Error on ActiveCell = (m1-1), would you please help..what is seems to be the problem? I appreciate you guys help on this

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Please attach a workbook with some example data. We don't know what ms1, ms2, ect are holding as values.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Range(M1).Value is not a number

    This is your code copied from above, inserted inside VBA tags using the green VBA button at the top of the post editor.
    [VBA]Sub C_how_many_to_insert()
    Sheets("Copied sorted values").Select
    Range("B2").Select
    Do Until ActiveCell.Offset(1, 0).Value = "x"

    ms1 = ActiveCell.Offset(0, 1)
    ms2 = ActiveCell.Offset(1, 1)

    If ms2 - ms1 > 1 Then
    ActiveCell.Value = (ms2 - ms1) - 1
    ActiveCell.Offset(1, 0).Select
    Else: ActiveCell.Offset(1, 0).Select
    End If
    Loop

    Range("B2").Select
    Do Until ActiveCell.Value = "x"
    p1 = ActiveCell.Offset(0, 2)
    p2 = ActiveCell.Offset(1, 2)

    If p1 <> p2 Then
    ActiveCell = 13 - ActiveCell.Offset(0, 1)
    ActiveCell.Offset(1, 0).Select
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Loop

    Range("D2").Select
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(-1, -3).Select
    Do
    p1 = ActiveCell.Offset(0, 3)
    p2 = ActiveCell.Offset(-1, 3)
    m1 = ActiveCell.Offset(0, 2)
    If p1 <> p2 And m1 <> 1 Then
    ActiveCell = (m1 - 1)
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop Until (ActiveCell.Address = "$A$1")

    Cells.Select
    Cells.EntireColumn.AutoFit

    Range("A2").Select
    End Sub[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The final column selection is into the bottom of Column A, which cell has the value "x", soi the first assignment of m1 is "x", not a number.
    [VBA]Range("D2").Select
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(-1, -3).Select 'Selects Col "A". Last Row[/VBA]

    Try changing that bit of code to
    [VBA]ActiveCell.Offset(-1, -1).Select[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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