+ Reply to Thread
Results 1 to 14 of 14

Looking to run a Private Sub Macro

  1. #1
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Looking to run a Private Sub Macro

    Hi,

    I want to run a Private Sub Macro, the code is as below:

    Please Login or Register  to view this content.
    This is basically required to compare values in 2 columns of a sheet with rows from 2 to 664 and based on the If loop if the condition is met then populate the target column with a specific statement.

    Can anyone please help me how to execute this macro

    Much appreciate the helper

    Regards

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Ruel #3 requires code tags. I have added them for you because you are a new user. --6StringJazzer
    Last edited by 6StringJazzer; 01-23-2014 at 03:29 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Looking to run a Private Sub Macro

    First, see my note in your post.

    Second, Worksheet_Change will be executed automatically any time any cell in the worksheet changes. That means a new value is entered into a cell, or a new formula is put into a cell. (It will not be executed if an existing formula results in a different value.)

    Third, there are numerous problems with this one line of code.

    Please Login or Register  to view this content.
    Rather than try to list and fix each one, it would be better to start over and explain what you are trying to do in detail. Your description uses the word "loop" but there is no loop in this code.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    Please use code tags when posting. Not sure about what you require but does this help?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Looking to run a Private Sub Macro

    how to run this?

    When i click on F5 it is asking me to create a macro and when I do that a new VB window opens

    I am trying to compare values in 2 columns and based on these values enter in a 3rd column the statement present in the query above.

    hope this clarifies

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    You apparently know how to access the Worksheet Change event based on Post#1? Replace the code you have with the suggestion I made on a copy of the sheet and see if it performs as you want. If you need further help let us know.

  6. #6
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Looking to run a Private Sub Macro

    to be more precise i want to compare the values in column V & column Z as per the rule above and print the result statement in column AD
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    Quote Originally Posted by potter185 View Post
    to be more precise i want to compare the values in column V & column Z as per the rule above and print the result statement in column AD
    What does "Os" stand for. In Column V I don't see "Os" in any of the cells. I guess "Ach" means achieve? What statement goes into Column AD?

  8. #8
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Looking to run a Private Sub Macro

    Os means Outstanding and Ach means achieves. the statement that goes into AD is "Movement from Os in '13 to Ach in '14"

    Hope this helps

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    I have added the Change Event code to your test file. See if this is what you want.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    Here is the code as well.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Looking to run a Private Sub Macro

    how should i run this private sub macro by calling this in another macro? can you please help me with the command for that

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    No it is set-up to run on Sheet1. If you type in Outstanding in Column V and the coinciding row in Column Z is Achieves then Column AD will populate with the phrase you wanted. Vice Verse if you type in Achieves in Column Z and the coinciding row in Column V is equal to Outstanding then Column AD will populate. Isn't that what you wanted?

  13. #13
    Registered User
    Join Date
    01-23-2014
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Looking to run a Private Sub Macro

    the problem that I am facing now is that this is working only when i change the data in any of the 2 columns and if the condition is met the result is displayed

    however I have a pre populated set of data. how do i ensure that with this input the responses get populated automatically

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Looking to run a Private Sub Macro

    Maybe:

    Please Login or Register  to view this content.
    This is a non event approach.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] how to run macro( Private sub)
    By var in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2012, 12:18 AM
  2. running a private sub macro
    By NALDO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2012, 06:44 PM
  3. [SOLVED] Calling a private macro
    By Nick Smith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-08-2006, 09:20 AM
  4. re : Possible to run private sub macros by writing another private
    By ddiicc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-26-2005, 12:05 AM
  5. Private Sub Running Other Private Sub Inadvertently
    By Ross Culver in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2005, 09:06 PM

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