macro help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know that I can create a macro that will monitor a specific cell, and once
that cell equals the contents of another cell, an event will occur. The event
that I would like to occur would be for the row to be hidden. I've worked
just a very little bit with macros, so I'm looking for help in creating this
macro.
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Columns("C:C").EntireColumn.Hidden = True Then
Exit Sub
Else
If Range("C1").Value = "hide" Then
Columns("C:C").Select
Selection.EntireColumn.Hidden = True
End If
End If
End Sub
 
I'm afraid that I am in a little over my head here. I appreciate the help. If
I copy and paste this macro as is into a macro that I create, it doesn't
work. Do I need to replace (ByVal Target As Range) with data?

Please be patient with me. I'm taking baby steps here, lol.
 
The type of macro that you need is referred to as an "Event" macro. This
type of macro is triggered to fire (execute) upon the occurrence of some
event. Excel recognizes many events. In your case you would use a
Worksheet_Change event macro. Such a macro MUST be placed in the sheet
module of the sheet you want to work on. You would not place this type of
code in the middle of any other macro that you have in a regular module.
This type of macro is a stand-alone macro and it will fire if any change is
made to the contents of any cell in the entire sheet. The "Target" that you
see in the first row of the macro is the cell that changed.
Because this macro fires with any change to any cell in the sheet, it stands
to reason that you will want to limit the macro action to a change in any of
just a few cells, maybe just one cell. You do that with lines like:
If IsEmpty(Target.Value) Then Exit Sub
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
The first will stop all action by the macro if the change in the contents of
the cell was to make it blank.
The second line stops all action by the macro if the Target cell is not A1.
For your purposes, you would then have something that looks like:
If Target.Value = Range("C5").Value Then
Target.EntireRow.Hidden = True
End If
I hope this is of some help to you. HTH Otto
 
Back
Top