LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default listbox selection to load to new form

Private Sub CmdSearch_Click()
Dim sh As Worksheet
Dim rng As Range, firstAddress As String
Dim SearchTxt As String
SearchTxt = TxtCaseName.Text

If TxtCaseName.Text = "" Then
GoTo ErrorHandler
End If

Set sh = Worksheets("Shelter")
Set rng = sh.Cells.Find(What:=SearchTxt,
After:=sh.Cells.Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

If Not rng Is Nothing Then
firstAddress = rng.Address
Do
Set rng = sh.Cells.FindNext(rng)
FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name
Loop While Not rng Is Nothing And rng.Address < firstAddress
End If

Set sh = Worksheets("Dependency")
Set rng = sh.Cells.Find(What:=SearchTxt,
After:=sh.Cells.Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

If Not rng Is Nothing Then
firstAddress = rng.Address
Do
Set rng = sh.Cells.FindNext(rng)
FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name
Loop While Not rng Is Nothing And rng.Address < firstAddress
End If

If TxtCaseName.Text = "" Then
GoTo ErrorHandler
End If

Set sh = Worksheets("TPR")
Set rng = sh.Cells.Find(What:=SearchTxt,
After:=sh.Cells.Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

If Not rng Is Nothing Then
firstAddress = rng.Address
Do
Set rng = sh.Cells.FindNext(rng)
FrmSelection.LboxSelect.AddItem (rng) & " " & sh.Name
Loop While Not rng Is Nothing And rng.Address < firstAddress
End If
If FrmSelection.LboxSelect.ListCount = 1 Then
Unload Me
FrmSelection.Show
Else
Unload Me
FCreate.Show
End If
ErrorHandler:
MsgBox "Please Type a Name", vbInformation, " No Names found"
End Sub

Is the SearchCode From FSearch ( userForm1)
It Pulls up Another Form ( FormSelect)
Wich has LboxSelect( ListBox)


Private Sub CmdSelect_Click()
Dim r As Range
Dim ws As Worksheet
Dim SearchTxt As String
Dim Row As Integer

If Me.LboxSelect.Text = "" Then
GoTo ErrorHandler
Else
Search (LboxSelect.Text)
End If
ErrorHandler:
MsgBox "Please Select One", vbOKOnly, "Error"
End Sub


Is The Selection Button It calls My Search Function

Private Function Search(strToSearch As String)
Dim sh As Worksheet
Dim rng As Range, firstAddress As String
Dim SearchTxt As String
SearchTxt = strToSearch
For Each sh In ThisWorkbook.Worksheets

Set rng = sh.Cells.Find(What:=SearchTxt, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)

If Not rng Is Nothing Then
GoTo ErrorHandler
Else
Found
End If
Next sh
ErrorHandler:
MsgBox "Error" & strToSearch & "Not Found"

End Function and here is where my Issues begin
When It calls The Function to Do What i need it to do It wont Activate
the Sheet

Private Function Found(StrList As String)
Dim SearchTxt As String
Dim rng As Range
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
SearchTxt = FrmSelection.LboxSelect.Text
If FrmSelection.LboxSelect.Text = "" Then
GoTo ErrorHandler2
Else
Set rng = sh.Cells.Find(What:=SearchTxt, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)


If Not rng Is Nothing Then
sh.Activate
' My Code to Enable or Disable Textboxes and to Fill TextBoxes goes
Here
Else
GoTo ErrorHandler2
End If
End If
Next sh
End Sub

I am doing this right correct? I mean, This is my First Time ever
using Functions and Im still Learning so i really dont know :|



 
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
How to load a listbox in a userform? Martin Excel Discussion (Misc queries) 3 July 25th 07 03:16 PM
Listbox selection creates form Jennifer Excel Programming 6 March 9th 06 07:50 AM
Which User Form Listbox selection just checked? Don Wiss Excel Programming 3 October 27th 05 01:52 AM
Load data into a listbox Jennifer Excel Programming 1 June 26th 05 12:57 PM
Listbox initialized on workbook load Kandi Excel Programming 5 December 21st 04 05:19 PM


All times are GMT +1. The time now is 03:47 PM.

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

About Us

"It's about Microsoft Excel"