+ Reply to Thread
Results 1 to 4 of 4

Retaining Worksheet name as string

  1. #1
    Registered User
    Join Date
    01-14-2004
    Location
    Va Beach, VA
    Posts
    71

    Retaining Worksheet name as string

    Hello,
    I've created code that allows the user to select a file to open and select a worksheet to copy and make a new worksheet from it. However I am unable to hold the previous worksheet name as a variable. This is needed a few steps down in the macro for inserting a vlookup formula that uses a reference to the original worksheet?
    HTML Code: 
    Is there a way to capture the name of the previous worksheet and retain throughout the macro?

    [HTML][/Sub insertformulas()
    With Range("b4")
    Dim shname As String
    shname = ActiveSheet.name

    .Formula = "=VLOOKUP($a4,'" & shname & "'!A:A,1,FALSE)"
    '.AutoFill Destination:=Range("b4:b" & LastRow)
    End With
    End SubHTML]
    Last edited by jimrosser; 05-07-2019 at 12:23 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Retaining Worksheet name as string


    Hi !

    As each worksheet has a Name property …

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Retaining Worksheet name as string

    Collect the name at the correct time as a string

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-14-2004
    Location
    Va Beach, VA
    Posts
    71

    Re: Retaining Worksheet name as string

    Thanks for the help, I rigged nigelog's code and made it work.

+ 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. Subtract count on worksheet B from worksheet A based on a found string in area
    By TheOneWeDreamOf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2019, 05:16 AM
  2. [SOLVED] Replace string with another string from another worksheet (like decode)
    By sugee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2013, 02:05 AM
  3. worksheet object as string - loop statement in worksheet index
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 12:27 PM
  4. Replies: 1
    Last Post: 01-25-2010, 12:48 PM
  5. Retaining macro functionality when publishing worksheet as an HTML file
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2009, 11:27 AM
  6. Retaining number format in a text string
    By bngms in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-27-2007, 11:31 AM
  7. Replies: 1
    Last Post: 06-29-2005, 12:05 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