VBA is row the same put X

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,177
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi, I am looking for a VBA solution to check to see if every value in the row is the same. I am trying to learn. If the row has a blank cell then the row is not the same. When it finds it please put an x at the end if the row.
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>ID</th><th>2010</th><th>2011</th><th>2012</th><th>2013</th><th> </th></tr></thead><tbody>
<tr><td>111</td><td>190111</td><td>190111</td><td>190111</td><td>190111</td><td>x</td></tr>
<tr><td>222</td><td>190111</td><td> </td><td> </td><td>190111</td><td> </td></tr>
<tr><td>333</td><td>190411</td><td>190411</td><td>190411</td><td>150311</td><td> </td></tr>
<tr><td>444</td><td>190111</td><td> </td><td>190111</td><td>190111</td><td> </td></tr>
<tr><td>555</td><td>191011</td><td>191011</td><td>191011</td><td>191011</td><td>x</td></tr>
</tbody></table>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Do you really need VBA for this as you can achieve it easy enough with formula? Drag/copy the formula in F2 down.

Excel Workbook
ABCDEF
1ID2010201120122013
2111190111190111190111190111x
3222190111190111
4333190411190411190411150311
5444190111190111190111
6555191011191011191011191011x
Sheet1
 
Upvote 0
If you would like VBA here is one way.

=remains(B2:E2)
then copy down

Code:
Function remains(r As Range) As String
remains = ""
    For Each xcell In r
        If WorksheetFunction.CountIf(r, xcell) = 4 Then
            remains = "x"
        End If
    Next
End Function
 
Upvote 0
Why would you use a VBA function to replace a normal formula?
I can understand to a certain degree using a VBA procedure if you already have some code you want to slot the code into but I can see no reason to create a function to do what a basic formula already does :confused:
 
Upvote 0
Further to what MARK858 has said, what is the point of looping through the range & using countif :confused:
The Countif will return the same result for each iteration of the loop.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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