ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to store values in a 2 dimensional array (https://www.excelbanter.com/excel-programming/438724-how-store-values-2-dimensional-array.html)

vicky

how to store values in a 2 dimensional array
 
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_Rennie[_3_]

how to store values in a 2 dimensional array
 

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/sh...d.php?t=172487

Microsoft Office Help


Dave Peterson

how to store values in a 2 dimensional array
 
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 wrote:

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/sh...d.php?t=172487

Microsoft Office Help


--

Dave Peterson

D_Rennie[_4_]

how to store values in a 2 dimensional array
 

cheers for pointing that out. I had it a little confused now understand
:)


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

Microsoft Office Help


Alex Ngo

how to store values in a 2 dimensional array
 
On Jan 23, 10:09*am, D_Rennie wrote:
cheers for pointing that out. I had it a little confused now understand
:)

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

Microsoft Office Help


Thanks for that!


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com