Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 35 of 35

Thread: Sleeper: Macro from Sub to Function question

  1. #21
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    It's because you're calling NewHIres without the parameter. It requires a range.


    Private Sub Worksheet_Change(ByVal Target As Range)
    NewHires "A1:C20"
    End Sub

  2. #22
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    So what if I want the range to be the same as what the function calls for (i.e. rng As Range)??

    A new column is added each month and I wouldn't want anyone to have to change the code everymonth...And I don't want to make the range to the end if it is unefficient.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #23
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Also getting a Type mismatch with a range type of "C2:C44"....????




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  4. #24
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Whoops, my bad. You need to call it something like this:


    Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim myRange As Range
    Set myRange = Worksheets("Finding text in Comments").Range("C2:C44")
    NewHires myRange
    End Sub



  5. #25
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by xCav8r
    Whoops, my bad. You need to call it something like this:


    Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim myRange As Range
    Set myRange = Worksheets("Finding text in Comments").Range("C2:C44")
    NewHires myRange
    End Sub

    or more probably


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myRange As Range
        Set myRange = Worksheets("Finding text in Comments").Range( _
            Cells(1, Target.Column), Cells(1, Target.Column).End(xlDown))
        NewHires myRange
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #26
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Those both work pretty good...xCav8r's is a little too specific for the range. And xld's works only when a change has been made to a cell value in the column that has the changed comment. I think I'm approaching this the wrong way.

    I want to make this so that when a comment is changed, and ONLY a comment is changed, to recalculate the formula in that column immediately. I thought I could just get away with the event procedures that you guys gave me (which I REALLY appreciate, BTW). But if the user solely changes an amount of new hires in a particular column (each column is a month, btw) and never changes anything in that column (cell values), then it will never show up. And I know I could just use a different event procedure such as Workbook_Activate or something, but I kind of wanted to make it instant.

    So I'll try to figure out something if I can...keep me posted if you guys think of anything. Otherwise thanks for ALL the help, well appreciated !!
    And if I think of anything, I'll post it. It may take a bit, though, seeing that I'm such a novice at VBA (and some formulas as well).




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #27
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by malik641
    ..I want to make this so that when a comment is changed, and ONLY a comment is changed, to recalculate the formula in that column immediately..
    No can do hoss. Excel does not recognize this as an 'event'. Kinda stinks, I know. Same with cell formatting (and THAT'S been a pain in my bum..). If you want instant-type results, you'll need to have this information in a column/cell.

  8. #28
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Grrr......I'll think of SOMETHING. I mean, what's an engineer for? lol

    Quote Originally Posted by firefytr
    No can do hoss. Excel does not recognize this as an 'event'. Kinda stinks, I know. Same with cell formatting (and THAT'S been a pain in my bum..). If you want instant-type results, you'll need to have this information in a column/cell.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  9. #29
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    LOL!

    You want my honest opinion? If you're trying to calculate something, a comment is not the best place for it. I think I would take the time to restructure it as so you can enter this data in an adjacent column.

  10. #30
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Trust me, I've thought that over plenty of times....but my range of columns that I have to change is from C to CQ....yeah, no thanks. And I guess I COULD change it only from this month on...but I kinda want to keep things consistent, so that's why I'm stuck doing this junk the way I am. The way I have it setup right now is to select the cells to evaluate, then run a macro (I made it as easy as I could by making a custom button to press). But I wanted to make it THAT much more efficient with this new function feature....
    Maybe this is what they'll have to deal with...We'll see.

    Quote Originally Posted by firefytr
    LOL!

    You want my honest opinion? If you're trying to calculate something, a comment is not the best place for it. I think I would take the time to restructure it as so you can enter this data in an adjacent column.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  11. #31
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Private Sub Worksheet_Change(ByVal Target As Range)
        NewHires Target
    End Sub

  12. #32
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Oops - hit that quick reply button without noticing page 2!!

    ... okay, I get it ... more coffee ...

  13. #33
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Have you thought of showing the data in a summary sheet instead? You could display a total # new hires for each month rather than using the comments.

  14. #34
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Well the reason for the comments is because there is not just new hires. There are terminations (Involuntary, and Voluntary) and there are transfers and it's just a dumb layout in my opinion. I would have set this up WAY differently. But this was made like 2 years ago...I just started working at my job for like 3 months, so I have to work with what I have. And I really don't want to do an overhaul.

    I spoke with the main user and he said it would be fine to make the sheet calculate all the values in each column upon a workbook_open event. So I'll be toying with that today. He also wants me to make a dialog box to pop-up when you press "Insert Comment" either from the right-click or the Insert->Insert Comment menu. In the dialog box he wants me to set it up sort of like the way conditional format's dialog box is set-up....I've never done a dialog box before...but I don't have a deadline, so I can take my time. I put the details in another thread "Userform pop-up when insterting a comment" if you want to check it out.

    So I'm going to have fun with that today!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  15. #35
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    If you created your own menu/toolbar/button/whatever, you could create your own userform and then make any events you want to off that. Otherwise, there is no event attached to inserting/deleting/adjusting comments. If you're still trying to go that way, it's a dead end.

    I'd suggest the custom menu and userform method. That would give you full control over everything the user picks from there. And I'd still suggest having the new hires data go into actual cells..

Posting Permissions

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