Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Listbox and Array questions

With a 2 column listbox, user is able to input values
to column 2 via a text box. How may I test that all
entries in col 2 have been made before the
OkButton_Click enables them to leave the form, please?

I am struggling to understand the basics of arrays, and
know that it is important to do so.
Here is very inefficient working code which I'm sure is
ideally suited to arrays:

For Each Cell In .Range("G1:G250")
For Each c In .Range("A1:A250")
If Cell.Value = c.Value Then
Cell.Offset(0, 1).Value = c.Offset(0, 1).Value
End If
Next
Next

I would be very grateful for help with this particular
situation, and also any links to primers on arrays.

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Listbox and Array questions

Hi Stuart,

Just checking. Are you trying to make sure the user does
not enter a value that already exists in the ListBox? Or
are you trying to disable/enable the OK button depending
on what the user has entered into the TextBox? Just trying
to get a clearer picture of what you need.

Thanks,
James S

-----Original Message-----
With a 2 column listbox, user is able to input values
to column 2 via a text box. How may I test that all
entries in col 2 have been made before the
OkButton_Click enables them to leave the form, please?

I am struggling to understand the basics of arrays, and
know that it is important to do so.
Here is very inefficient working code which I'm sure is
ideally suited to arrays:

For Each Cell In .Range("G1:G250")
For Each c In .Range("A1:A250")
If Cell.Value = c.Value Then
Cell.Offset(0, 1).Value = c.Offset(0, 1).Value
End If
Next
Next

I would be very grateful for help with this particular
situation, and also any links to primers on arrays.

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date:

18/09/2003
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Listbox and Array questions

Stuart

here is an example of getting the data into an array:

Sub TestArray1()
'abcdefghijklmnopqrstuvwxyz in cells G1 to G26
Dim vArray() As Variant
vArray = Application.Transpose(Range("G1:G26"))
MsgBox vArray(1) & " " & vArray(26)
End Sub

Note that to get column data into an array it must be transposed.

For your particular example, the following code seems to work and is quite
quick:

Sub TestArray2()
Dim AvArray() As Variant
Dim BvArray() As Variant
Dim GvArray() As Variant
Dim HvArray(1 To 250) As Variant
Dim AIndex As Integer
Dim GIndex As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

AvArray = Application.Transpose(Range("A1:A250"))
BvArray = Application.Transpose(Range("B1:B250"))
GvArray = Application.Transpose(Range("G1:G250"))

For GIndex = 1 To 250
For AIndex = 1 To 250
If GvArray(GIndex) = AvArray(AIndex) Then
HvArray(GIndex) = BvArray(AIndex)
End If
Next AIndex
Next GIndex

Range("H1:H250") = Application.Transpose(HvArray)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

It is obviously constrained to 250 rows as that was what your example was
using. Note that this is 62500 comparisons.

Regards

Trevor


"Stuart" wrote in message
...
With a 2 column listbox, user is able to input values
to column 2 via a text box. How may I test that all
entries in col 2 have been made before the
OkButton_Click enables them to leave the form, please?

I am struggling to understand the basics of arrays, and
know that it is important to do so.
Here is very inefficient working code which I'm sure is
ideally suited to arrays:

For Each Cell In .Range("G1:G250")
For Each c In .Range("A1:A250")
If Cell.Value = c.Value Then
Cell.Offset(0, 1).Value = c.Offset(0, 1).Value
End If
Next
Next

I would be very grateful for help with this particular
situation, and also any links to primers on arrays.

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Listbox and Array questions

Actually, that's a good point, and both are relevent!
I guess the ideal wold be:
a:
only load lb.col2 if the textbox value is valid
AND is a unique value to lb.col2
b:
then after each 'a:' test if lb.col2 is full (ie contains
a value for each lb.col1 value) AND then enable
the OkButton.

It's referencing col2 in the listbox that's my first
problem.

Regards and thanks.

"James S" wrote in message
...
Hi Stuart,

Just checking. Are you trying to make sure the user does
not enter a value that already exists in the ListBox? Or
are you trying to disable/enable the OK button depending
on what the user has entered into the TextBox? Just trying
to get a clearer picture of what you need.

Thanks,
James S

-----Original Message-----
With a 2 column listbox, user is able to input values
to column 2 via a text box. How may I test that all
entries in col 2 have been made before the
OkButton_Click enables them to leave the form, please?

I am struggling to understand the basics of arrays, and
know that it is important to do so.
Here is very inefficient working code which I'm sure is
ideally suited to arrays:

For Each Cell In .Range("G1:G250")
For Each c In .Range("A1:A250")
If Cell.Value = c.Value Then
Cell.Offset(0, 1).Value = c.Offset(0, 1).Value
End If
Next
Next

I would be very grateful for help with this particular
situation, and also any links to primers on arrays.

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date:

18/09/2003



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Listbox and Array questions

Many thanks, both for the the explanation, and
the code for my example.

Regards.

"Trevor Shuttleworth" wrote in message
...
Stuart

here is an example of getting the data into an array:

Sub TestArray1()
'abcdefghijklmnopqrstuvwxyz in cells G1 to G26
Dim vArray() As Variant
vArray = Application.Transpose(Range("G1:G26"))
MsgBox vArray(1) & " " & vArray(26)
End Sub

Note that to get column data into an array it must be transposed.

For your particular example, the following code seems to work and is quite
quick:

Sub TestArray2()
Dim AvArray() As Variant
Dim BvArray() As Variant
Dim GvArray() As Variant
Dim HvArray(1 To 250) As Variant
Dim AIndex As Integer
Dim GIndex As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

AvArray = Application.Transpose(Range("A1:A250"))
BvArray = Application.Transpose(Range("B1:B250"))
GvArray = Application.Transpose(Range("G1:G250"))

For GIndex = 1 To 250
For AIndex = 1 To 250
If GvArray(GIndex) = AvArray(AIndex) Then
HvArray(GIndex) = BvArray(AIndex)
End If
Next AIndex
Next GIndex

Range("H1:H250") = Application.Transpose(HvArray)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

It is obviously constrained to 250 rows as that was what your example was
using. Note that this is 62500 comparisons.

Regards

Trevor


"Stuart" wrote in message
...
With a 2 column listbox, user is able to input values
to column 2 via a text box. How may I test that all
entries in col 2 have been made before the
OkButton_Click enables them to leave the form, please?

I am struggling to understand the basics of arrays, and
know that it is important to do so.
Here is very inefficient working code which I'm sure is
ideally suited to arrays:

For Each Cell In .Range("G1:G250")
For Each c In .Range("A1:A250")
If Cell.Value = c.Value Then
Cell.Offset(0, 1).Value = c.Offset(0, 1).Value
End If
Next
Next

I would be very grateful for help with this particular
situation, and also any links to primers on arrays.

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 19/09/2003


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array to Populate ListBox Problem pallaver Excel Discussion (Misc queries) 1 July 25th 08 08:50 AM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Excel CHALLENGE...3 questions(indirect,rank,array formula)... Mlowry Excel Worksheet Functions 8 August 1st 05 07:34 AM
Array Functions - Two Questions MDW Excel Worksheet Functions 3 January 12th 05 06:54 PM
Array Questions DWTSG Excel Programming 3 July 24th 03 06:53 PM


All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"