In Excel v2010, I have a workbook with 30 worksheets, each named after a sales rep (firstname lastname) e.g. Bob Smith. Each sheet is protected with a password; I'm declaring variables in a module for both the username (which is the same as the sheet name) and password for the sheet.
The username variables are U1, U2, etc.
The password variables are Up1, Up2, etc.
The following example is just for the 1st 2 sheets:
Public Const U1 As String = "Bob Smith"
Public Const U2 As String = "Linda Jones"
Public Const Up1 As String = "BS" 'password for Bob Smith
Public Const Up2 As String = "LJ" 'password for Linda Jones
Currently I have code that refers to each sheet for various purposes. For instance, if I want to unprotect each sheet, I have this code which uses the variables above:
While that code works, I'd much rather do this in a For Next loop; something like the following:
Dim x as string, y as string, i as integer
For i = 1 to 30
x = "U"&i
y = "Up"&i
But of course that doesn't work.
And again, I'm referring to sheets for other purposes, not just to protect/unprotect.
Many thanks for your expertise.
I remember answering a similar question for you on 8th Jan. Can you please clarify how this question is different from the earlier question.
If you expect my solution to work as part of a larger macro / code, then I think it'll be better if you could share the whole macro and tell me the precise requirement.
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here