Willdcards in Sheet Name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • if1467
    New Member
    • Feb 2008
    • 25

    Willdcards in Sheet Name

    Hi,

    I am using VB 6.3 for excel and i have the foillowing code:

    Code:
    Sheets.Add
    Sheets("Sheet1").Select
    Sheets("Sheet1").Name = "Results"
    The problem is that when I re-run the program the sheet that gets created is incremented by 1, so renaming it doesn't work.

    I tried using a wildcard for the numerical charactor (below), but it didn't work.

    Code:
    Sheets.Add
    Sheets("Sheet*").Select
    Sheets("Sheet*").Name = "Results"
    Does anyone have an idea for a solution that would make this work?
  • ubentook
    New Member
    • Dec 2007
    • 58

    #2
    The sheet that is added becomes the active sheet.
    So just rename the active sheet...

    Sheets.Add Count:=1
    ActiveSheet.Nam e = "Results"

    Note that each sheet in an Excel workbook must have a unique name - you cannot have two sheets named Results.

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Sheets indexes can be Strings or Integers

      if your sheets are
      Sheet1, Sheet2, Sheet3, Sheet4, Sheet5

      you can check them inside a loop using an integer with:

      [CODE=vb]dim i as integer
      for i = 1 to 5
      sheets(i).name = "MySheet" & i
      next[/CODE]

      or using a string:

      [CODE=vb]dim i as integer
      dim Str1 as string
      for i = 1 to 5
      Str1 = "Sheet" & i
      sheets(Str1).na me = "MySheet" & i
      next[/CODE]

      well

      HTH

      Comment

      Working...