+ Reply to Thread
Results 1 to 2 of 2

How to pass a variable from one module to another

  1. #1
    Registered User
    Join Date
    02-14-2014
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    28

    How to pass a variable from one module to another

    Hello, I have a repetitive process that I'd like to try to simplify coding wise. The basics is to take a string from inside module A and send it to Module B and have procedures executed. Example Below:

    Private Sub Show_Inputs_Click()

    If Show_Inputs.Value = True Then

    Dim Last_Row As Integer
    Dim Range_Unlock As String

    'Find the last non-blank cell in column K
    Last_Row = Cells(Rows.Count, 11).End(xlUp).Row

    If Last_Row = 4 Then
    Range_Unlock = "C4,E4:J4"
    Range(Range_Unlock).Select
    Selection.Locked = False
    Range("$AA$1").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Range("$C$4").Select
    End If

    If Last_Row = 5 Then
    Range_Unlock = "C4,E4:J4" & ",D5:J5"
    Range(Range_Unlock).Select
    Selection.Locked = False
    Range("$AA$1").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Range("$C$4").Select
    End If

    If Last_Row > 5 Then
    Range_Unlock = "C4,E4:J" & Last_Row & ",D5:J" & Last_Row
    Range(Range_Unlock).Select
    Selection.Locked = False
    Range("$AA$1").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Range("$C$4").Select
    End If

    End Sub


    I'd like to change it to something like:

    Private Sub Show_Inputs_Click()

    If Show_Inputs.Value = True Then

    Dim Last_Row As Integer
    Dim Range_Unlock As String

    'Find the last non-blank cell in column K
    Last_Row = Cells(Rows.Count, 11).End(xlUp).Row

    If Last_Row = 4 Then
    Range_Unlock = "C4,E4:J4"
    Call RangeChange (Range_Unlock)
    End If

    If Last_Row = 5 Then
    Range_Unlock = "C4,E4:J4" & ",D5:J5"
    Call RangeChange (Range_Unlock)
    End If

    If Last_Row > 5 Then
    Range_Unlock = "C4,E4:J" & Last_Row & ",D5:J" & Last_Row
    Call RangeChange (Range_Unlock)
    End If

    End Sub




    Sub RangeChange (Range_Unlock)
    Range(Range_Unlock).Select
    Selection.Locked = False
    Range("$AA$1").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Range("$C$4").Select
    End Sub


    How do I pass the Range_Unlock variable from the Sub Show_Inputs_Click to Sub RangeChange?

    Thanks!

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to pass a variable from one module to another

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ 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. Save workbook as variable/pass argument to another module
    By crossfitciaran in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-06-2015, 07:40 PM
  2. Pass Variable From UserForm to Module
    By BLLMRC in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-24-2013, 12:41 PM
  3. [SOLVED] Pass date variable to another procedure/module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2013, 10:16 PM
  4. [SOLVED] pass variable for user form module to function
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2012, 10:10 PM
  5. Pass variable between subs within module
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2010, 04:58 PM
  6. [SOLVED] Pass variable from module to userform and back
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2006, 11:50 AM
  7. Pass combo box value to string variable in module
    By magix in forum Excel General
    Replies: 1
    Last Post: 12-15-2005, 11:50 AM

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