how to store values in a 2 dimensional array

V

vicky

i want to store Sheet name and its corresponding password in a 2
dimension array . hope anyone can provide a code snippet for storing
sheet name and its corresponding password and also code for popping
out values from an array . i am newbie to vba . providin code wil be
really helpful . i need something like

i need to store the values in this fashion

Array(0) ----- > should contain sheetname and its password value
Array(1) ----- > should contain sheetname and its password value

while popping out i shuld put the values in 2 variables .

sheet name in Variable 1 its corresponding password in
Password in Variable 2 ................

hope anyone can provide a code for this ........
 
D

D_Rennie

hello.

You can use this as a method for fulling up the 2 demitional array
Code
-------------------
Sub FullArray()

Dim ShtNm_Pass(1 To 4, 1 To 4): 'allowed for 4 sheets
Dim x As Long

With ThisWorkbook

For x = 1 To 4
'Loading the sheet names
ShtNm_Pass(x, 1) = .Sheets(x).Name
'if passwords are stored on a sheet (used the name hidden in this case)
ShtNm_Pass(x, 2) = Sheets("Hidden").Cells(x, 1)
Next x

'full the second half of the array (password manually)
' ShtNm_Pass(1, 2) = "1"
' ShtNm_Pass(2, 2) = "2"
' ShtNm_Pass(3, 2) = "3"
' ShtNm_Pass(4, 2) = "4"


'cheeking the array has been fulled. You dont need this only here for testing
For x = LBound(ShtNm_Pass, 1) To UBound(ShtNm_Pass, 1)
Debug.Print ShtNm_Pass(x, 1)
Debug.Print ShtNm_Pass(x, 2)
Next x

End With

End Su
-------------------


as the debug.print you can pull out the information form the array whe
ever you like. eg ShtNm_Pass(1, 1) would be the sheet name an
ShtNm_Pass(1, 2) would be the corrosponding password.

hope this help
 
D

Dave Peterson

Since you're only keeping track of two things for each item, you don't need to
use "1 to 4" for each dimension.

Dim ShtNm_Pass(1 To 4, 1 To 2)
would be sufficient.




D_Rennie said:
hello.

You can use this as a method for fulling up the 2 demitional array
Code:
--------------------
Sub FullArray()

Dim ShtNm_Pass(1 To 4, 1 To 4): 'allowed for 4 sheets
Dim x As Long

With ThisWorkbook

For x = 1 To 4
'Loading the sheet names
ShtNm_Pass(x, 1) = .Sheets(x).Name
'if passwords are stored on a sheet (used the name hidden in this case)
ShtNm_Pass(x, 2) = Sheets("Hidden").Cells(x, 1)
Next x

'full the second half of the array (password manually)
' ShtNm_Pass(1, 2) = "1"
' ShtNm_Pass(2, 2) = "2"
' ShtNm_Pass(3, 2) = "3"
' ShtNm_Pass(4, 2) = "4"


'cheeking the array has been fulled. You dont need this only here for testing
For x = LBound(ShtNm_Pass, 1) To UBound(ShtNm_Pass, 1)
Debug.Print ShtNm_Pass(x, 1)
Debug.Print ShtNm_Pass(x, 2)
Next x

End With

End Sub
--------------------

as the debug.print you can pull out the information form the array when
ever you like. eg ShtNm_Pass(1, 1) would be the sheet name and
ShtNm_Pass(1, 2) would be the corrosponding password.

hope this helps

--
D_Rennie
------------------------------------------------------------------------
D_Rennie's Profile: 1412
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=172487

Microsoft Office Help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top