VBA: Box a cell if value equals another cell

Brigitta

New Member
Joined
Jun 12, 2015
Messages
2
Hello excel gurus,

Could you help me, please, with a macro that does the following:
In the range for e.g A1:J20 it checks the cells if there are equal to cells in range A30:J30 and draws a border around the correct value.

More specific; it looks in A1:A20, finds the value that is equal to cell A30 and draws a border around it. Next column, until loops through all A:J.

The code is asigned to a button in sheet 1 and does the same for sheets 1 to 5.

Thank you for your help! I know it's quite complex...
Brigitta
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try:
Code:
Sub DelRows()
    Application.ScreenUpdating = False
    Dim rng As Range
    Dim x As Long
    For x = 1 To 10
        For Each rng In Range(Cells(1, x), Cells(20, x))
            If rng = Cells(30, x) Then
                With rng.Borders(xlEdgeLeft)
                    .LineStyle = xlContinuous
                End With
                With rng.Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                End With
                With rng.Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                End With
                 With rng.Borders(xlEdgeRight)
                    .LineStyle = xlContinuous
                End With
            End If
        Next rng
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here is another macro you can try...
Code:
Sub BorderAroundRows1to20ifEqualToRow30()
  Dim C As Long
  Application.ReplaceFormat.Clear
  Application.ReplaceFormat.Borders(xlEdgeLeft).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeRight).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeTop).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeBottom).Weight = xlMedium
  For C = 1 To 10
    Cells(1, C).Resize(20).Replace Cells(30, C).Value, "", xlWhole, , , , False, True
  Next
  Application.ReplaceFormat.Clear
End Sub
 
Upvote 0
Sorry. I missed the part about the 5 sheets.
Code:
Sub DelRows()
    Application.ScreenUpdating = False
    Dim rng As Range
    Dim ws As Worksheet
    Dim mySheet As Worksheet
    Dim x As Long
    Dim y As Long
    For y = 1 To 5
        For Each ws In Sheets
            If ws.CodeName = "Sheet" & y Then
                ws.Activate
                For x = 1 To 10
                    For Each rng In Range(Cells(1, x), Cells(20, x))
                        If rng = Cells(30, x) Then
                            With rng.Borders(xlEdgeLeft)
                                .LineStyle = xlContinuous
                            End With
                            With rng.Borders(xlEdgeTop)
                                .LineStyle = xlContinuous
                            End With
                            With rng.Borders(xlEdgeBottom)
                                .LineStyle = xlContinuous
                            End With
                            With rng.Borders(xlEdgeRight)
                                .LineStyle = xlContinuous
                            End With
                        End If
                    Next rng
                Next x
            End If
        Next ws
    Next y
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry. I missed the part about the 5 sheets.
Hmm, so did I...
Code:
Sub BorderAroundRows1to20ifEqualToRow30()
  Dim C As Long, WS As Long
  Application.ReplaceFormat.Clear
  Application.ReplaceFormat.Borders(xlEdgeLeft).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeRight).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeTop).Weight = xlMedium
  Application.ReplaceFormat.Borders(xlEdgeBottom).Weight = xlMedium
  For WS = 1 To 5
    With Sheets(WS)
      For C = 1 To 10
        .Cells(1, C).Resize(20).Replace .Cells(30, C).Value, "", xlWhole, , , , False, True
      Next
    End With
  Next
  Application.ReplaceFormat.Clear
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,739
Messages
6,057,081
Members
444,904
Latest member
SelamT

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