Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default New to userforms - can you help with this code?

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 477
Default New to userforms - can you help with this code?

maybe i = CInt(frmGetJob.TextBox1.Value)
HTH


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default New to userforms - can you help with this code?

Worked wonderfully for me, my guess would be either that your textbox is not
named Textbox1, but more likely that the value you are putting in it is not
an integer as you have i dimensioned. Any other data?
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default New to userforms - can you help with this code?

Hi John,
The textbox is named txtRef
and as I am quite new to this I don't understand your statement:
"but more likely that the value you are putting in it is not
an integer as you have i dimensioned"
The value to be input by the user will always be a number
any further help appreciated

"John Bundy" wrote:

Worked wonderfully for me, my guess would be either that your textbox is not
named Textbox1, but more likely that the value you are putting in it is not
an integer as you have i dimensioned. Any other data?
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default New to userforms - can you help with this code?

I just meant to make sure they were passing a number. You are setting i =
frmGetJob.TextBox1.Value, if your textbox is named txtRef then it should be
i = frmGetJob.Txtref.Value


--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi John,
The textbox is named txtRef
and as I am quite new to this I don't understand your statement:
"but more likely that the value you are putting in it is not
an integer as you have i dimensioned"
The value to be input by the user will always be a number
any further help appreciated

"John Bundy" wrote:

Worked wonderfully for me, my guess would be either that your textbox is not
named Textbox1, but more likely that the value you are putting in it is not
an integer as you have i dimensioned. Any other data?
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default New to userforms - can you help with this code?

John
thanks for your continued help, however this is now starting to drive me
nuts as I still can't get the full code to work. To sumerise, this is what I
want the code to do.

1) User inputs a number into the Textbox of the userform (frmGetJob / txtRef)
2) if no number is entered and Search is clicked - Msg box with error
displayed
3) if number entered is not found through column A of DATA worksheet - msg
box displayed
4) if number entered is found through column A of DATA worksheet, that whole
row is copy/paseted to row2 of the SEARCH JOB RESULTS worksheet

Thats it really!

The code I am trying to get to work is:

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")
If txtRef.Text = "" Then
MsgBox ("Please enter a reference number to search for")
Exit Sub
End If

Sheets("Search Job Results").Activate
nextrow = Application.WorksheetFunction.CountA(Range("A:A")) + 1

i = frmGetJob.txtRef.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox ("No job with the number " & i & _
" has been found, please try again! ")

Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number

End Sub

Can I ask you to try and get this to do as I require before I go and push
the Christmas Tree over!!
many thanks
Anthony

"John Bundy" wrote:

I just meant to make sure they were passing a number. You are setting i =
frmGetJob.TextBox1.Value, if your textbox is named txtRef then it should be
i = frmGetJob.Txtref.Value


--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi John,
The textbox is named txtRef
and as I am quite new to this I don't understand your statement:
"but more likely that the value you are putting in it is not
an integer as you have i dimensioned"
The value to be input by the user will always be a number
any further help appreciated

"John Bundy" wrote:

Worked wonderfully for me, my guess would be either that your textbox is not
named Textbox1, but more likely that the value you are putting in it is not
an integer as you have i dimensioned. Any other data?
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default New to userforms - can you help with this code?

If the user puts a "number" in a textbox, it becomes text. If your Find
statement is looking for a match in a range of integers (real numbers) it
will not find a match because i will be "text" rather than a "number"
although i will look like a number in the textbox. If you look at it in VBA
it will probably have quote marks around it to indicate that it is type text.
That is what John is trying to tell you.

"Anthony" wrote:

John
thanks for your continued help, however this is now starting to drive me
nuts as I still can't get the full code to work. To sumerise, this is what I
want the code to do.

1) User inputs a number into the Textbox of the userform (frmGetJob / txtRef)
2) if no number is entered and Search is clicked - Msg box with error
displayed
3) if number entered is not found through column A of DATA worksheet - msg
box displayed
4) if number entered is found through column A of DATA worksheet, that whole
row is copy/paseted to row2 of the SEARCH JOB RESULTS worksheet

Thats it really!

The code I am trying to get to work is:

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")
If txtRef.Text = "" Then
MsgBox ("Please enter a reference number to search for")
Exit Sub
End If

Sheets("Search Job Results").Activate
nextrow = Application.WorksheetFunction.CountA(Range("A:A")) + 1

i = frmGetJob.txtRef.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox ("No job with the number " & i & _
" has been found, please try again! ")

Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number

End Sub

Can I ask you to try and get this to do as I require before I go and push
the Christmas Tree over!!
many thanks
Anthony

"John Bundy" wrote:

I just meant to make sure they were passing a number. You are setting i =
frmGetJob.TextBox1.Value, if your textbox is named txtRef then it should be
i = frmGetJob.Txtref.Value


--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi John,
The textbox is named txtRef
and as I am quite new to this I don't understand your statement:
"but more likely that the value you are putting in it is not
an integer as you have i dimensioned"
The value to be input by the user will always be a number
any further help appreciated

"John Bundy" wrote:

Worked wonderfully for me, my guess would be either that your textbox is not
named Textbox1, but more likely that the value you are putting in it is not
an integer as you have i dimensioned. Any other data?
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Anthony" wrote:

Hi all,

I have a userform called GetJob in which the user inputs a reference number
into TextBox1
I want this number to be searched for through column A of the DATA worksheet
and then copy the whole row of data when found and paste into row 2 of the
Search Job Results worksheet
I am a little stuck with my code as I can't get the user's input number to
be searched for
Here is what I have so far

Private Sub cmdSearch_Click()

Dim i As Integer
Dim iRow As Integer
Dim Cel As Range
Dim wks1 As Worksheet, wks2 As Worksheet
Dim lLastRow As Long
'On Error GoTo err_handler
Set wks1 = ThisWorkbook.Worksheets("Data")
Set wks2 = ThisWorkbook.Worksheets("Search Job Results")

i = frmGetJob.TextBox1.Value

On Error Resume Next
Set Cel = wks1.Columns("A:A").Find _
(What:=i, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Cel Is Nothing Then
MsgBox "No job with the number " & i & _
" has been found, please try again! "
Exit Sub
End If
On Error GoTo err_handler
iRow = Cel.Row
wks1.Cells(iRow, 1).EntireRow.Copy Destination _
:=wks2.Cells(2, 1)

Exit Sub

err_handler:
MsgBox Error, , "Err " & Err.Number
End Sub

the code gets stuck on this
i = frmGetJob.TextBox1.Value

any help appreciated to make it work

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
Userforms Zaahir Excel Programming 4 October 25th 06 12:53 PM
Help with Userforms Panagiotis Marantos Excel Discussion (Misc queries) 2 July 25th 06 04:26 PM
I need some help with userforms T.c.Goosen1977 Charts and Charting in Excel 0 June 30th 06 09:29 AM
Userforms keep popping up, need code to stop it rammieib Excel Programming 3 February 24th 06 05:24 PM
Help with UserForms mb Excel Programming 3 October 28th 05 06:02 AM


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

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"