Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ruben Jackson   on Sep 07 In MS Office Category.

  
Question Answered By: Hayden Evans   on Sep 07

I found some code  for what I want to do which is working with arrays.
And when I tested it worked ok until it started to populate the listbox.



Private Sub cmbFindAll_Click()

Dim FirstAddress As String

Dim strFind As String 'what to find

Dim rSearch As Range 'range to search

Dim fndA, fndB, fndC, fndD, fndE, fndF As String

Dim head1, head2, head3, head4, head5, head6 As String 'heading s
for list

Dim i As Integer

i = 1

Set rSearch = Sheet1.Range("a6", Range("a65536").End(xlUp))

strFind = Me.TextBox1.Value

With rSearch

Set c = .Find(strFind, LookIn:=xlValues)

If Not c Is Nothing Then 'found it

c.Select

'load the headings

head1 = Range("a5").Value

head2 = Range("b5").Value

head3 = Range("c5").Value

head4 = Range("d5").Value

head5 = Range("e5").Value

With Me.ListBox1

MyArray(0, 0) = head1

MyArray(0, 1) = head2

MyArray(0, 2) = head3

MyArray(0, 3) = head4

MyArray(0, 4) = head5

MyArray(0, 5) = head6

End With

FirstAddress = c.Address

Do

'Load details into Listbox

fndA = c.Value

fndB = c.Offset(0, 1).Value

fndC = c.Offset(0, 2).Value

fndD = c.Offset(0, 3).Value

fndE = c.Offset(0, 4).Value

fndF = c.Offset(0, 5).Value

MyArray(i, 0) = fndA

MyArray(i, 1) = fndB

MyArray(i, 2) = fndC

MyArray(i, 3) = fndD

MyArray(i, 4) = fndE

MyArray(I, 5) = fndF

i = i + 1

Set c = .FindNext(c)

Loop While Not c Is Nothing And c.Address <> FirstAddress



End If

End With

'Load data into LISTBOX

Me.ListBox1.List() = MyArray



End Sub





There is works though the listbox doesn’t fill in the information for head5
or head6. Also fndE and fndF doesn’t get inputed in the listbox aswell.



Option Explicit

Dim MyArray(7, 5)

Public MyData As Range, c As Range



This is how the person who made  the original code set the Array. Can you
help me understand how to make this code work.



I am having a search being done from a text  box. And then hitting a find
button. Then a message box shows up that tells me how many names it found.
After that I click on the following command button find  All the listbox
should be filled in with the array information.



Thankyou for helping me. I am looking at your code to see if it will make my
task easier. Basically I am making  an input form  for my students that I
teach to input grades and do searches for certain tests and scores so I can
more easily provide the information to the office desk where I work . I
work in Japan at a college as an English teacher.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on cmdFind for multiple Text and Combo Boxes Or get search suggestion and latest updates.


Tagged: