Miss - match error ?

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Hi,


Column A has a list of three letter codes placed in each cell and is periodically updated.


The Sub Procedure below is designed to check the most recently added code against the codes already on the list. If the code is the same as any added before then it is deleted from the list. When the Sub Procedure is executed a Mismatch Error occurs at the part of the underlined statement.


Please will someone show me where I am going wrong .


Code:
Sub Check_for_previous_occurance_of_code()
      Sheets("User Interface").Select
      Range("a9").End(xlDown).Select
      [U]If Selection.Value = Range(Selection.Offset(-1, 0), Selection.End(xlUp)).Value[/U] Then Selection.ClearContents
  End Sub
Thanks,

Rob
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi Rob
It looks like you are selecting the entire column of data and then asking the code to use part of the entire selection to check itself....kinda dosen't make sense

Try
Code:
Sub delem()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
    For r = lr - 1 To 9 Step -1
        If Range("A" & lr).Value = Range("A" & r).Value Then Rows(lr).Delete
    Next r
End Sub
You could change this to a Worksheet_selectionchange event so that it checks as soon as the data is input.

Another tip, try and avoid the use of Select.Selection in your code. simply remove them.
So,
Code:
Sheets("User Interface").Select
      Range("a9").End(xlDown).Select
      If Selection.Value
would be
Code:
Sheets("User Interface").Range("a9").End(xlDown).Value........
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top