+ Reply to Thread
Results 1 to 4 of 4

Transferring a dynamically named string variable to another string variable.

Hybrid View

Concorde Rules Transferring a dynamically... 10-09-2012, 03:54 AM
Concorde Rules Re: Transferring a... 10-09-2012, 03:59 AM
Andy Pope Re: Transferring a... 10-09-2012, 04:00 AM
Concorde Rules Re: Transferring a... 10-09-2012, 04:08 AM
  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2008
    Posts
    8

    Transferring a dynamically named string variable to another string variable.

    Hi, this is a complex one to explain but I'll try. (Also hampers googling!)

    I have six spreadsheets with names, I need to loop through these spreadsheets in order to clear the contents before I then insert some new data.

    I need the [Active_Sheet = "Sheet_" & iSheet] line to transfer the *contents* of the variable (for example: "Sheet_3") to Active_Sheet, rather than the name of the variable it currently does.

    
    Dim Sheet_1 As String
    Dim Sheet_2 As String
    Dim Sheet_3 As String
    Dim Sheet_4 As String
    Dim Active_Sheet As String
    
    Sheet_1 = "Monkies"
    Sheet_2 = "Bananas"
    Sheet_3 = "Sheep"
    Sheet_4 = "Dogs"
    
    
    Do Until iSheet = 6
    
         Active_Sheet = "Sheet_" & iSheet
    
        Set Excel_Sheet = Excel_Workbook.Sheets(Active_Sheet)
        Call Clear_Cells(Excel_Sheet)
    
        iSheet = iSheet + 1
        
    Loop
    Thoughts?

    Thanks!

  2. #2
    Registered User
    Join Date
    09-27-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2008
    Posts
    8

    Re: Transferring a dynamically named string variable to another string variable.

    Right, after reading through this forum I stumbled across the answer! An array!

    http://www.mrexcel.com/forum/excel-q...ble-names.html

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: Transferring a dynamically named string variable to another string variable.

    When not use an array for the sheet names?

    Dim SheetName(1 To 4) As String
    Dim Active_Sheet As String
    Dim iSheet As Integer
    
    SheetName(1) = "Monkies"
    SheetName(2) = "Bananas"
    SheetName(3) = "Sheep"
    SheetName(4) = "Dogs"
    
    iSheet = 1
    Do Until iSheet = 5
    
         Active_Sheet = SheetName(iSheet)
    
        Set Excel_Sheet = Excel_Workbook.Sheets(Active_Sheet)
        Call Clear_Cells(Excel_Sheet)
    
        iSheet = iSheet + 1
        
    Loop
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    09-27-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2008
    Posts
    8

    Re: Transferring a dynamically named string variable to another string variable.

    Thanks, yes.

    I found my perseverance of reading rather than googling!

+ 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