+ Reply to Thread
Results 1 to 3 of 3

Refreshing earlier stated variable?

  1. #1
    Forum Contributor
    Join Date
    04-30-2010
    Location
    Denmark
    MS-Off Ver
    Office 365
    Posts
    215

    Refreshing earlier stated variable?

    If I have some variables that changes a lot while running through the code, what is the proper way to "refresh" those variables.

    For instance lets say I have a couple variable like below and I use the same code many times:

    lsheetname = Sheets("Sheet1").Cells(lRow, lCol).Value
    lheadline = Sheets("Sheet1").Cells(lRow + 1, lCol).Value
    If lsheetname = "" Or lheadline = "" Then
    lLastRow = 0
    Else
    lmatchcol = WorksheetFunction.Match(lheadline, Sheets(lsheetname).Range("1:1"), 0)
    lLastRow = Sheets(lsheetname).Cells(Rows.Count, lmatchcol).End(xlUp).Row
    End If

    Should this code be put in a function or in another sub and what would that function/sub then look like, if I need to use the returned values in my primary sub?

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Refreshing earlier stated variable?

    You could make those variables Public, then put that code exactly as it is into a subroutine and call that whenever you need to reset them.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    04-30-2010
    Location
    Denmark
    MS-Off Ver
    Office 365
    Posts
    215

    Re: Refreshing earlier stated variable?

    You pointed me in the right direction - cheers!

+ 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] Only those values are required which are to the left of stated value
    By raju.r.083 in forum Excel General
    Replies: 12
    Last Post: 12-05-2017, 09:19 AM
  2. Obect Required error when variable already set earlier in sub?
    By mrbusto71 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2016, 09:00 PM
  3. Replies: 1
    Last Post: 02-23-2012, 05:49 PM
  4. Replies: 4
    Last Post: 11-02-2011, 07:58 AM
  5. Creating groups based on stated preference?
    By Nosnibor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2010, 08:10 AM
  6. Replies: 0
    Last Post: 02-13-2009, 03:56 PM
  7. Matching cells (RE-STATED)
    By GARY in forum Excel General
    Replies: 0
    Last Post: 02-14-2006, 03:00 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