MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Mismatch Error

Posted by Sam on June 21, 2001 11:27 AM

I keep getting a mismatch error with the macro below if someone has ideas on how to fix it that would be great.


Sub test()

LastRow = ActiveSheet.UsedRange.Rows.Count
Do Until Selection.Row > LastRow
If Selection.Value = "AL_Ship_Motion" Then
cCell = ActiveCell.Address
Range(cCell).Offset(0, 7).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
LastRow = LastRow - 1
Selection.Offset(1, 0).Select
End If

End Sub

Posted by Barrie Davidson on June 21, 2001 11:36 AM

Can you include your variable declarations also?


Posted by Sam on June 21, 2001 11:39 AM

Do You mean at the begining where you write dim ... as ...? If so then there isn't any for that macro.

Posted by Sam on June 21, 2001 11:42 AM

i looked again and the macro can goes through with out an error the first time but after that the error comes up.

Posted by Jerid on June 21, 2001 11:51 AM

Your problem is that after you run through your loop once and you get to the line that selects 4 cells, that selection remains and the error occurs when you try to test the value of one cell.

You are testing the value of one cell
>If Selection.Value = "AL_Ship_Motion" Then
>cCell = ActiveCell.Address
But the last time you looped through your code you selected 4 cells

You need to move your selection after paste.


Posted by Barrie Davidson on June 21, 2001 12:09 PM

See Jerid's answer.

Posted by Sam on June 21, 2001 12:19 PM


Thanks guys that took care of it.