+ Reply to Thread
Results 1 to 10 of 10

Automatically run VBA

  1. #1
    Registered User
    Join Date
    03-06-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    14

    Automatically run VBA

    I have the following VBA code:

    Please Login or Register  to view this content.
    I want Sheet2-A to update in real time. That is, whenever I add something to 1-A, I want it to automatically execute without me having to click "Run."

    Is this possible?
    Last edited by nmicon; 05-15-2009 at 11:05 AM.

  2. #2
    Forum Contributor vikas.bhandari's Avatar
    Join Date
    04-07-2006
    Location
    Delhi, India
    MS-Off Ver
    Office 2007 and 2010
    Posts
    303

    Re: Automatically run VBA

    Go to VBA Editor. Press ctrl+R to make the project explorer visible. In the project explorer, find the VBA Project(your workbook). There, double click the entry with "1-A". It will look like Sheet1 (1-A).

    In the editor, paste the code :

    Please Login or Register  to view this content.
    HTH,
    Vikas
    Last edited by vikas.bhandari; 05-15-2009 at 09:38 AM. Reason: Editing signature. Forgot to add it :P

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically run VBA

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    03-06-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Automatically run VBA

    I insterted what you wrote in Sheet1

    However, I'm getting the following error:
    Compile Error:
    Sub or Function not defined.
    Thoughts?
    Last edited by nmicon; 05-15-2009 at 10:50 AM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Automatically run VBA

    Why do you need to duplicate the data?

    Use the worksheet_change event
    Please Login or Register  to view this content.
    Copy the code
    Select the worksheet in which you want the code to run
    Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
    Where the cursor is flashing, choose Edit | Paste

  6. #6
    Registered User
    Join Date
    03-06-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Automatically run VBA

    Thank you so much! Works perfectly!

  7. #7
    Registered User
    Join Date
    05-19-2009
    Location
    Wash D.C.
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Automatically run VBA

    Hi,

    Does anyone know if its possible to automatically execute a sub() that you have built for a sheet in VB editor? I would love to be able to open the spreadsheet and have the sub() execute without me manually telling it to. I have about 12 sheets in the book and each sheet has its own sub to establish a connection to my sql server and execute a stored procedure to return a value to the sheet. So you can see how much of a pain it would be to have to manually execute the sub() for each sheet.

    I'm trying this in Excel2007 and have posted something similar in another thread but I cant find my previous post.

    I definately would have pasted the link here.
    I promise I won't do that again.
    Very Sorry.

    Any comments/help would really be appreciated.
    chris

  8. #8
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Automatically run VBA

    Chris,
    I can't help you with your code, but to find your other post, just go to Search, Advanced Search, enter your username in the right side text box (Search by User Name) and click Search Now. It will find every thread you posted.

    Hope this helps.

    Andrew

  9. #9
    Registered User
    Join Date
    05-19-2009
    Location
    Wash D.C.
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Automatically run VBA

    Quote Originally Posted by drewship View Post
    Chris,
    I can't help you with your code, but to find your other post, just go to Search, Advanced Search, enter your username in the right side text box (Search by User Name) and click Search Now. It will find every thread you posted.

    Hope this helps.

    Andrew
    TYTY!!!
    http://www.excelforum.com/excel-gene...nt-sheets.html

  10. #10
    Registered User
    Join Date
    05-19-2009
    Location
    Wash D.C.
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Automatically run VBA

    I think I got it!

    The problem was in my WITH statement. I replaced 'ActiveSheet' with the actual sheet I wanted to work with (called 'Sheet1') and added Sheet1 to destination:= part as well.

    --old code--
    With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=sqlstring)

    --new code--

    With Sheet1.QueryTables.Add(Connection:=connstring,
    Destination:=Sheet1.Range("A1"), Sql:=sqlstring)


    I'll post these results in the other thread as well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1