Finding Last Row/Column to Hide other Cells

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am trying to finding the last row with a value.
-I know how to do this typically by using "xlUp" but for some reason it is stopping at a cell that does not contain a value but just a change in color.
-I am now trying to find a different way to go about this.
Instead, I want to go Row by row to find the last column of every Row(starting at 9) until the column number equals 4.

Below is my code which I realize does not really make sense, but maybe shows you a little of what I am thinking.

VBA Code:
Sub HiddenRows()
Dim StartRow As Long, LastColumn As Long
LastColumn = Worksheets("Project - Gantt Chart").Cells(StartRow, Columns.Count).End(xlLeft).Column 'find the last column
StartRow = Worksheets("Project - Gantt Chart").Cells(9,)
For newRow = StartRow To 100 Step 1                        'newRow is the counter. It will count from the last row to row 1 with a -1 step size.

    Next
End Sub
 

Attachments

  • updated.PNG
    updated.PNG
    48.4 KB · Views: 8

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This line of code will not work:
VBA Code:
LastColumn = Worksheets("Project - Gantt Chart").Cells(StartRow, Columns.Count).End(xlLeft).Column 'find the last column
change xlLeft into xlToLeft
Whenever {xlUp} is not working as expected, the cell on the last row is not empty. The interiour color of a cell is not the cause of your problem.
 
Upvote 0
Thank you, any idea why the attached code is not working? It is giving me "application-defined or object-defined error".


VBA Code:
Sub HiddenRows()
Dim CheckRow As Long, HiddenRng As Range
HiddenRng = Range("CheckRow:100")
For CheckRow = 9 To 100 Step 1      'newRow is the counter. It will count from the last row to row 1 with a -1 step size.
    If Worksheets("Project - Gantt Chart").Cells(CheckRow, Columns.Count).End(xlToLeft).Column = 4 Then
    Worksheets("Executive Summary").Rows(HiddenRng).Hidden = True
    
End If
Next
End Sub
 
Upvote 0
Thank you, any idea why the attached code is not working? It is giving me "application-defined or object-defined error".
You are welcome. Below I will make some remarks on your code. Note that I do not claim to be complete.
HiddenRng = Range("CheckRow:100")
Ranges are referenced with the SET statement as in Set HiddenRng = xxxxx , so this line will error.
"CheckRow:100" as used by you is a string which has to be a name of an (existing) address, as in "A1:B2"
Worksheets("Executive Summary").Rows(HiddenRng).Hidden = True
This line will error since the Rows collection expects a number (or a placeholder or variable that represents a number).
You've given the variable HiddenRng the dimension of a Range, so HiddenRng will be "Nothing".
 
Upvote 0
-I know how to do this typically by using "xlUp" but for some reason it is stopping at a cell that does not contain a value but just a change in color.
Are you sure that the cell doesn't contain a formula returning ""?
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,738
Members
449,116
Latest member
alexlomt

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