VBA: MsgBox Warning if row is hidden

ThomasA1993

New Member
Joined
Sep 10, 2019
Messages
6
Hi all

I'm new here and kinda of new to VBA, but trying to learn.

I have a bit of a tough one (for me at least).

I am trying to write a code that can do the following.

Whenever a row is hidden manually if the row contains a value greater or smaller than zero, and not text string in columns H, J and L - i need msgbox to pop up and say "Warning - you are hiding a data".

Is this possible - and can it work if multiple rows are hidden together? :)

I would have posted my own attempt - but i am not even close to one yet.
 
it is the;
"For each c" which in the error occurs
I get "Run-time error '1004': Method 'Intersect' of object'_Global' failed"
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If it is happening when you plug the data into the sheet that doesn't have the code, then it means that the code is trying to intersect cells in 2 different sheets, which can't happen.
I thinnk that this should fix it by only allowing the code to run when the sheet with the code is active, if you have 2 or more workbooks open with the same sheet names then it might still error out.
Code:
Option Explicit
Private Sub Worksheet_Calculate()
[COLOR="#FF0000"]If Me.Name <> ActiveSheet.Name Then Exit Sub[/COLOR]
Dim c As Range, rng As Range, rlist As String
For Each c In Intersect(Selection.EntireRow, Range("H:H,J:J,L:L"))
    If c.EntireRow.Hidden And IsNumeric(c.Value) And c.Value <> 0 Then
        If rng Is Nothing Then
            Set rng = c
        Else
            Set rng = Application.Union(rng, c)
        End If
    End If
Next
    If Not rng Is Nothing Then MsgBox "You are hiding data in cells" & vbCrLf & rng.Address(0, 0), vbCritical
End Sub
 
Upvote 0
I tried again and started by unhiding all rows, and then i had no problem - but the debug occured on the following lines.

I dont remember the debug code i think however it was 13. but i am not sure :)
I don't see any lines of code referenced/posted.
Is there an image I am not seeing?
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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