PDA

View Full Version : [SOLVED:] Select the first two similar values



Klartigue
08-29-2011, 12:34 PM
A1
A1
A1
A2
A2
A2
A2
A3
A3
A3
A..

A1, A2, A3, etc.. represents different bids for one item. For example, A1 is an item and each row for A1 represents a different bid. I am trying to write a macro that selects only the first two A1, the first two A2, etc..

Thanks for your help

Bob Phillips
08-29-2011, 01:30 PM
Off the top


With Activesheet
Lastrow = .Cells(.Rows.Count,"A"),End(xlUp).Row
For i = LastRow To 3 Step -1
If Application.Countif(.Columns(1),.Cells(i, "A").Value) > 2 Then
.Rows(i).Delete
End If
Next i
End With

Klartigue
08-29-2011, 01:34 PM
Thanks. Now what if there are more than 3 items, it could go from A1 to A30, etc...

Will the code above work?

Bob Phillips
08-29-2011, 01:46 PM
Why don't you try it and see.

Klartigue
08-30-2011, 02:32 PM
Lastrow = .Cells(.Rows.Count,"A"),End(xlUp).Row

Excel is saying there is a syntax error with the above line??

Thanks for the help

Bob Phillips
08-30-2011, 03:01 PM
Typo, it should be


Lastrow = .Cells(.Rows.Count,"A").End(xlUp).Row

Klartigue
08-31-2011, 06:02 AM
It works, thank you! I just have a couple more questions with this project.

So now I have:

A1
A1
A2
A2
A3
A3
etc..

How do I get a macro to highlight in yellow the top A1, top A2, top A3, and rename the bottom A1, A2, and A3 the word "cover"

Bob Phillips
08-31-2011, 06:12 AM
Surely, after running the code, there is only one of each.

Klartigue
08-31-2011, 10:10 AM
Sub highlight()
Dim lastrow As Long
Dim i As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
If Application.CountIf(.Range("A1").Resize(i), .Cells(i, "A").Value) = 2 Then


i know it starts like this..i just dont know how to rename a cell using a macro

Klartigue
08-31-2011, 10:36 AM
In the cell located in in column R, row 1 I would like to put the word "EVAL" ??

Thanks for your help

Klartigue
08-31-2011, 10:40 AM
Sub NameEval()
Range("R1").Select
ActiveCell.Value = "EVAL"
End Sub

Nevermind I figured it out!!

Bob Phillips
08-31-2011, 03:45 PM
You don't need to select



Sub NameEval()

Range("R1").Value = "EVAL"

End Sub