+ Reply to Thread
Results 1 to 3 of 3

reference a sheet with variable?

Hybrid View

pgag45 reference a sheet with... 05-15-2007, 02:28 PM
mikerickson I'm not sure what you are... 05-15-2007, 03:47 PM
cbanks in case its not sheet 1 05-15-2007, 04:08 PM
  1. #1
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I'm not sure what you are trying to do. Does it help to know that the last three lines do the same thing?

    Dim sheetName As String
    sheetName = "sheet1"
    
    Dim mySheet As Worksheet
    Set mySheet = ThisWorkbook.Sheets("sheet1")
    
    ThisWorkbook.Sheets("sheet1").Activate
    ThisWorkbook.Sheets(sheetName).Activate
    mySheet.Activate

  2. #2
    Registered User
    Join Date
    05-04-2006
    Posts
    24

    in case its not sheet 1

    if your sheet is labeled the same name as your workbook then this will work..

    Dim sheetname As String
    Dim i As String
    Dim j As String
    Dim k As String
    Dim sFileName As String
    
    j = 1
    i = ""
    
    'Show the open dialog and pass the selected _
    file name To the String variable "sFileName"
    sFileName = Application.GetOpenFilename
    'They have cancelled.
    If sFileName = "False" Then Exit Sub
    Workbooks.Open Filename:=sFileName
    
    
    Do Until k = "\"
    i = Right(sFileName, j)
    k = Left(i, 1)
    DoEvents
    j = j + 1
    Loop
    
    j = j - 1
    sheetname = Right(i, j)

+ 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