Results 1 to 6 of 6

Referencing Worksheet Using a Variable (New to VBA

Threaded View

thenewkidd Referencing Worksheet Using a... 05-03-2021, 07:48 PM
maniacb Re: Referencing Worksheet... 05-03-2021, 08:02 PM
thenewkidd Re: Referencing Worksheet... 05-03-2021, 08:36 PM
mgs73 Re: Referencing Worksheet... 05-03-2021, 08:20 PM
thenewkidd Re: Referencing Worksheet... 05-03-2021, 08:43 PM
thenewkidd Re: Referencing Worksheet... 05-03-2021, 08:52 PM
  1. #1
    Forum Contributor
    Join Date
    05-03-2021
    Location
    Nashville
    MS-Off Ver
    MS Office 365
    Posts
    189

    Referencing Worksheet Using a Variable (New to VBA

    I am quite new to VBA, while I can do simple "Macro Recording".
    I am trying to branch out and shorten unnecessary code.

    Background of what I am trying to do.

    I have a "database" for every month of the Year (so every tab is named JAN - DEC).

    To prevent having to write the same VBA 12 times referencing sheets("JAN").select all the way to sheets("DEC").select 48 times.
    (exaggeration but you get the gist) I want to be able to create a variable that references the sheet so that if I need to make changes, I am only changing one thing at the top of the code instead of looking at a long string of code and make changes to every line that has "sheets("JAN").select"

    Dim xstr as worksheet
    Set xstr = Worksheet("JAN")

    It seems when I do
    xstr.Select I get an "Debug" request at the line I have this code at.

    I'm sure this is something super easy. Just missing how to get variables to work for me to make coding a lot shorter and easier to update in one spot.

    Thanks in advance.
    Last edited by thenewkidd; 05-03-2021 at 08:53 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 10
    Last Post: 09-10-2018, 06:58 PM
  2. [SOLVED] Variable cell referencing a worksheet
    By MeBeMel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-06-2015, 09:54 AM
  3. referencing variable help
    By 13lack13lade in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-10-2014, 08:56 PM
  4. referencing a defined worksheet variable in a formula in vba
    By framptonl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2012, 08:13 PM
  5. Simple formula with variable names referencing another worksheet
    By gototcm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2012, 05:56 AM
  6. Variable referencing?
    By nasbcn in forum Excel General
    Replies: 2
    Last Post: 01-25-2008, 11:33 AM
  7. Referencing a variable in place of worksheet name
    By marksince1984 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-15-2006, 05:36 PM

Tags for this Thread

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