Hi,The below statement generally used for to find last row in a 1st Column(A- Column) and then assigning last row...
Hi, change the below statement:Thanks!
Hi, I have traced your code and found that the source file is not opened. Here is the updated VBA...
HI, Please find the following link to improve & optimize your VBA ccode. http://analysistabs.com/vba/optimize-code-run-macros-faster/ 1. Do save as your file...
hi, give this a try. Cell A1 will contain 120105, Cell G2 will contain the answer 1215
Hi,Here is the solution to disable message and to automatically update the links when you open a workbook. Please follow...
Hi, Here is the sample projects related to userform available in the following link. You can also download sample workbook...
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).