How to initiate code

guestuser

New Member
Joined
Mar 9, 2010
Messages
29
When I have edited links in a document, I want to activate a code. But it doesn’t activate.. what am I doing wrong??<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
It works if I go into the cell (F2), and then push enter.. (But I don't want the users to have to do that..)
<o:p></o:p>
<o:p>There might be many mistakes in this code.. I am a newbie..</o:p>
<o:p> </o:p>
<o:p></o:p>
Option Explicit<o:p></o:p>
<o:p> </o:p>
Private Sub Workbook_Open()<o:p></o:p>
'<o:p></o:p>
' Editlinks<o:p></o:p>
'<o:p></o:p>
Application.SendKeys ("%a")<o:p></o:p>
Application.SendKeys ("k")<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
:eek: SO FAR IT WORKS FINE... <o:p></o:p>
<o:p> </o:p>
Private Sub Worksheet_Change(ByVal target As Range)<o:p></o:p>
<o:p> </o:p>
Dim cScreens As Object<o:p></o:p>
Dim cOptional_S_F As Object<o:p></o:p>
Dim yes As Boolean<o:p></o:p>
<o:p></o:p>
If Range("cScreens") = ("yes") Then Rows("34:51").Hidden = False Else Rows("34:51").Hidden = True<o:p></o:p>
If Range("cOptional_S_F") = ("yes") Then Rows("24:33").Hidden = False Else Rows("24:33").Hidden = True<o:p></o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
:eek: This last part doesn’t start on its own.. I think I need to initiate it somehow..?<o:p></o:p>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Do you need the Change event?

Couldn't you just combine both sets of code?

The reason I think the 2nd code isn't getting triggered is because the 1st code isn't doing anything that will trigger the change event.

Not 100% sure though because I don't know what the first code is meant to do and seeing SendKeys is only only slightly rarer than them being recommended.:)
 
Upvote 0
the sendkeys opens the 'edit links' box. then the user can choose their file, and my workbook updates with the correct information. After that information has been updated (automatically, by lookups into their file), rows should be shown or hidden based on 2 cells. both cells will either be empty or have 'yes' in them (independent of each other).
how can I connect them? or activate the second code (events?) after the links have been updated?
 
Upvote 0
This works ine for me, I am not sure what your two objects are for

Code:
Private Sub Worksheet_Change(ByVal target As Range)

    Rows("34:51").Hidden = Me.Range("J1").Value = "yes"
    Rows("24:33").Hidden = Me.Range("J2").Value = "yes"

End Sub

This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.
 
Upvote 0
it doesn't work.. try having a different workbook where you change' yes' or just blanc. look up those cells in your new workbook with the code. when you change something in the other sheet, the workbook does not update the hidden/shown rows based on the new information..
 
Upvote 0
The change event is not triggered by formulas calculating, only by actual values being entered into cells. I suspect you want the Worksheet_Calculate event instead.
 
Upvote 0
Code:
Private Sub Worksheet_Calculate()

    Rows("34:51").Hidden = Me.Range("cScreens").Value = "yes"
    Rows("24:33").Hidden = Me.Range("cOptional_S_F").Value = "yes"

End Sub
for example.
 
Upvote 0
it's not working.. do I put it in the "module"? "this worksheet"? "name of the tab"?
I just get 'debug' and then my whole excel crashes..
 
Upvote 0
It needs to go into the code module for the sheet that contains the formulas. It's also worth turning events off to avoid a loop:
Code:
Private Sub Worksheet_Calculate()
   On Error Resume Next
   Application.Enableevents = False
    Rows("34:51").Hidden = Me.Range("cScreens").Value = "yes"
    Rows("24:33").Hidden = Me.Range("cOptional_S_F").Value = "yes"
   Application.Enableevents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

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