+ Reply to Thread
Results 1 to 2 of 2

Create a macro (module?) that activates in my userform code?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-18-2006
    Posts
    43

    Create a macro (module?) that activates in my userform code?

    Is there a way I can make :
        Dim MyDate, MyDay
        MyDate = Worksheets("Calc").Range("B1").Value
        MyDay = Day(MyDate)
    Sit in a module named as a macro with something I made up like "Sub RowSelector()"
    Sub RowSelector()
        Dim MyDate, MyDay
        MyDate = Worksheets("Calc").Range("B1").Value
        MyDay = Day(MyDate)
    End Sub
    and then call that macro to activate when I need it? So Instead of :
    Private Sub TextBox5_Change()
        Dim MyDate, MyDay
        MyDate = Worksheets("Calc").Range("B1").Value
        MyDay = Day(MyDate)
            Range("E" & MyDay).Value = Me.TextBox5.Value
    End Sub
    I would like have:
    Private Sub TextBox5_Change()
          Execute RowSelector      'I have no idea but just for example of what i need.
            Range("E" & MyDay).Value = Me.TextBox5.Value
    End Sub
    I am asking not only for this, but I have another set of instructions much larger that I need to be able to call in the same way.
    I could probably handle the bulk thsi current method is causing me here, but my other code I need to call repeatedly would be huge.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Bafa,

    Here is how...
    'Place this in the General Declarations section of the UserForm
    Sub RowSelector(ByVal NewValue As Variant)
    
        Dim MyDate, MyDay
    
          MyDate = Worksheets("Calc").Range("B1").Value
          MyDay = Day(MyDate)
    
            Range("E" & MyDay).Value = NewValue
    
    End Sub
    
    'TextBox5 event code
    Private Sub TextBox5_Change()
        RowSelector TextBox5.Value
    End Sub
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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