Function to hide row

Excelgoeroe

New Member
Joined
Feb 4, 2012
Messages
5
I am looking for a UDF that will hide a row on a condition. So not in a macro that needs an event, but in a formula:

=IF(A8=0;HideRow()) just as =IF(A8=0;Now())

I tried the following Function

Function RowHide(Arg1 As Integer) As Action


If Arg1 = 0 Then
ActiveSheet.Select
ActiveCell.Select
Selection.EntireRow.Hidden = True
End If

End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

I don't think you will be able to do that. See here for an introduction to UDF's:
Writing Your Own Functions In VBA

and note the following statement in the article:

A UDF can only return a value to the cell(s) whence it was called -- it must not modify the contents or formatting of any cell and must not modify the operating environment of Excel. If you attempt to change anything, the function will terminate immediately and return a #VALUE error to the calling cell.
 
Upvote 0
Hi thanks for your comment. You are completely right, this is what's happening.
Now, I am just curious how I can solve the basic wants to have a function to conditionally hide a row or column without a macro.
I have tried to use conditional formatting, but no luck so far.
Has anybody a suggestion?
 
Upvote 0
Welcome to the Board!

Same as with UDF's, Conditional Formatting can't perform physical functions like hiding rows. But you can try AutoFilter, which is a lot more efficient than trying to select/loop through rows anyway.

HTH,
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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