Solved

Run Macro When Cell Value = "X"

Posted on 2011-02-19
7
641 Views
Last Modified: 2012-05-11
When an "X" is entered in cell I13, I need it to trigger a macro that will unhide a specific row.  Macro name is "Unhide1"

Thanks
0
Comment
Question by:klitton7
  • 3
  • 3
7 Comments
 
LVL 45

Accepted Solution

by:
patrickab earned 50 total points
ID: 34934606
klitton7,

The code below is in the attached file. Place an x in I13 and it will unhide row 10.

Patrick
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range

Set rng = Me.Cells(13, "I")

If Not Intersect(rng, Target) Is Nothing Then
    If LCase(Target.Value) = "x" Then
        Rows("9:11").EntireRow.Hidden = False
    End If
End If

End Sub

Open in new window

Unhide-row-01.xls
0
 
LVL 1

Expert Comment

by:dev00790
ID: 34934675
This will unhide the 1st row when a user open the file, providing the cell specified has an "X", and that the 1st row is already hidden.

 
Option Explicit
Public rownum As Integer

'Row 1 must be hidden when opening file for below to work
'An "X" must be in the cell specified also when opening file.

Sub auto_open()

    rownum = 1
    
    If Cells(13, 9).Value = "X" Then
        Rows(rownum).EntireRow.Hidden = False
    Else
        'Put what you want to happen when cells(13,9) value is not "X" here
    End If

End Sub

Open in new window


Regards
Unhide-row.xls
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34934869
dev00790,

What worksheet is that supposed to work as you haven't specified it.

Patrick
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Expert Comment

by:dev00790
ID: 34935133
it's "sheet1"

dev00790
0
 

Author Closing Comment

by:klitton7
ID: 34935374
This worked great (no need to trigger a macro -
 I need to add to 7 other cells:
I15 unhide 16
I17 unhide 18
I20 unhide 21
J23 unhide 24
J25 unhide 26
J30 unhide 31
J32 unhide 33
Not sure how to do this - should I enter a new question to get this answerr?
0
 
LVL 1

Expert Comment

by:dev00790
ID: 34935468
You will need to ask a new question for that klitton7.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34936675
klitton7 - Thanks for the grade - Patrick
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now