Need VB help

E

Eric @ BP-EVV

I've got a spreadsheet that looks like the following:

location item weight type1 type2
A 1 5.50 M M
B 1 5.50 M M
A 2 6.60 M M
B 2 6.60 T M
A 3 7.00 M M
A 4 6.00 T M
B 4 6.00 M M
C 4 6.25 T M

What I need to do is this:

1. If item on row 1 = item on row 2, highlight both rows (or multiple rows
if the item exists in more than 2 locations)
2. If weight on row 1 <> weight on row 2 (for same item at different
locations), change text color of weight cells to bolded-red
3. For all other conditions, leave formatting as is.

I'm stuck trying to figure out how to do that through VB code.....any
throughts ?

Thanks !
 
S

StumpedAgain

Hey Eric,

I did the following on your example post and it works fine (unless I missed
something). Hope it helps!!

Sub ForEric()

Dim curselection As Range
Set curselection = Range("B2")

Do Until curselection = ""

If curselection Like curselection.Offset(1, 0) Then
curselection.EntireRow.Resize(2, 5).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

If curselection.Offset(0, 1) <> curselection.Offset(1, 1) Then
curselection.Offset(0, 1).Resize(2, 1).Select
Selection.Font.ColorIndex = 3
Selection.Font.Bold = True
End If
End If

Set curselection = curselection.Offset(1, 0)

Loop

End Sub
 
E

Eric @ BP-EVV

Hi SA - Thanks for your help....it worked great ! I have one more little
twist I think I'd like to work out that maybe you can help with too:

The first If loop of your code highights each of the matching rows, what
would need to change in the code so that for alternating sets of matching
rows the highlight color alternates between yellow and green ? In other
words,

In my original example below, the two rows with item 1 would be yellow, the
two rows for item 2 would be green, no highlight for the row with item 3, and
the three rows with item 4 would be yellow ?

Does that make sense ? That would make it much easier to read and see the
differences.

Thanks again for your help ! I do appreciate it !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top