0

I'm trying to write something where the user inputs the tab name of a worksheet in Excel and uses the tab name to get the sheet's codename before continuing through the code.

Logic
  • 5
  • 3
  • 1
    What good is a string var assigned to the worksheet's codename going to do? You cannot use the string like `strSheet1.Cells(1, 1)` or `Worksheets(strSheet1)` or really for anything else I can think of. You might be better to retrieve the ordinal index. –  Apr 19 '17 at 13:44
  • http://stackoverflow.com/q/25203173/1188513 – Mathieu Guindon Apr 19 '17 at 13:58

1 Answers1

1

Try something like below:

Dim ShtCodeName As String

ShtCodeName = Worksheets("YourSheetName").CodeName
Shai Rado
  • 33,032
  • 6
  • 29
  • 51
  • Is there a way to have it returned as a Worksheet that I can then use with commands like: ShtCodeName.UsedRange.Rows.Count – Logic Apr 19 '17 at 13:45
  • @Logic `CodeName` is just a `String`. `Worksheets("YourSheetName")` gets you the worksheet object you're after, so `Set sheet = Worksheets("YourSheetName")` and then you can do `sheet.UsedRange.Rows.Count`. – Mathieu Guindon Apr 19 '17 at 13:51
  • @Mat'sMug Thanks! – Logic Apr 19 '17 at 13:59