Another approach using dictionary [code] Private Sub UserForm_Initialize() Dim arr As Variant arr = GetDistinct(Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)) ListBox1.List =...
Thanks a lot PNRao for this great solution Another approach using collection [code] Private Sub UserForm_Initialize() Dim ws As Worksheet...
Thanks vaali... this is the data sheet1 data EID NAME PAY PayDay 14123 Joe1 $1,234.00 29-Jun-17 14124 Joe2...
HI, Here is the required macro to search a field and if value found copy the whole row into another...
I found a solution like this :Records in between two specific dates easily can be filtered using drop-down lists ....
I found a solution as follows: Watch the video to see how it's done and download example file : https://youtu.be/SZduAoOtiS0
I have sorted the above problem. Code is given below... [code] Sub seperate() Call CleanSheets MsgBox "1 of 10 Cleaning...
I am new to VBA and I am hiding rows with same the cell value across the row. I have eight columns in my test, but what happens if I have data across 100 columns and there are 500 rows, and I need to search all 100 columns down 500 rows, trying to find rows with the same repeating value across all cells (e.g. 10) and then hiding that particular row. I do not want to write ‘And’ 100 times in an IF statement.
Thanks so much.
Dim i As Long
For i = 1 To 50
'Cells in Column A have an account number
If Range("B" & i).Value = 0 And Range("C" & i).Value = 0 And Range("D" & i).Value = 0 And Range("E" & i).Value = 0 And Range("F" & i).Value = 0 And Range("G" & i).Value = 0 And Range("H" & i).Value = 0 Then
Rows(i).Hidden = True
Rows(i).Hidden = False
Hi, Here is the dynamic code for your requirement:
Dim i As Long
Dim startRow As Long
Dim endRow As Long
Dim startCol As Integer
Dim endCol As Integer
Dim totColumns As Integer
Dim NoOccur As Integer
'Inputs :Change it accordingly*****************
startRow = 1
endRow = 50
startCol = "A"
endCol = "G"
totColumns = 0
'1. Find #Total Columns
totColumns = Cells(1, endCol).Column - Cells(1, startCol).Column + 1
'2. By default make all rows visible
Rows(startRow & ":" & endRow).Hidden = False
'3. Now check for each row
For i = 1 To 50
'Check how many time the first cell is repeating in the cells of a row range
NoOccur = Application.WorksheetFunction.CountIf(Range(Cells(i, startCol), Cells(i, endRow)), Cells(i, startCol))
If NoOccur = totColumns Or NoOccur = 0 Then
Rows(i).EntireRow.Hidden = True 'Hide if the Coccurances are eaquals to total columns and or 0 (0=all cells are blank in the row range)
Thanks for your response PNRao. I appreciate your expertise and this site. Unfortunately, the code you submitted does not seem to hide the rows. I changed the columns on Line 26 to 2 and on Line 28 to 7 because the variables are declared as integers. I experimented with the totColumns variable by changing it different numbers and also leaving it at zero, and the macro still did not seem to hide the rows. I was wondering if you had any thoughts.
Could you please paste the modified VBA code.
Please share using the share button above.
If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.
Found the answer useful and wants to credit the user, then vote the answer (vote up).