Value NOT being input

C

Corey

The below code places valuies from the Sheet-"Data" into the Sheet-"Job card",
BUT, the Highlighted LINE value DOES NOT apear, WHY ??
Removing the 'On Error Resume Next' i get a Object Variable not set error.


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
UserForm2.Hide
With ActiveWorkbook.Worksheets("Job Card")
..Select
Dim rngFound As Range
' On Error Resume Next
With Worksheets("Data").Range("A:A")
Set rngFound = .Find(What:=UserForm2.ListBox1.Value, After:=.Range("A1"), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
Range("B2").Value = ListBox1.Value
Range("B6").Value = rngFound.Offset(0, 4).Value ' <===== Error here !!!
End With
' Preview worksheet to either Print of simply View
ActiveWindow.SelectedSheets.PrintPreview
' Clears all data that was brought in from sheet "InspectionData"
Dim c As Range
For Each c In Sheets("Job Card").UsedRange
If c.Locked = False Then
c.ClearContents
End If
Next
Sheets("NavigationPage").Activate
On Error GoTo 0
End With
Unload Me
Application.ScreenUpdating = True
End Sub

Help ??

Corey....
 
C

Corey

Never mind sussed it out.
Had a Custom value infront of the Numerical value, therefore the xlWhole did not find it.

The below code places valuies from the Sheet-"Data" into the Sheet-"Job card",
BUT, the Highlighted LINE value DOES NOT apear, WHY ??
Removing the 'On Error Resume Next' i get a Object Variable not set error.


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
UserForm2.Hide
With ActiveWorkbook.Worksheets("Job Card")
..Select
Dim rngFound As Range
' On Error Resume Next
With Worksheets("Data").Range("A:A")
Set rngFound = .Find(What:=UserForm2.ListBox1.Value, After:=.Range("A1"), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
Range("B2").Value = ListBox1.Value
Range("B6").Value = rngFound.Offset(0, 4).Value ' <===== Error here !!!
End With
' Preview worksheet to either Print of simply View
ActiveWindow.SelectedSheets.PrintPreview
' Clears all data that was brought in from sheet "InspectionData"
Dim c As Range
For Each c In Sheets("Job Card").UsedRange
If c.Locked = False Then
c.ClearContents
End If
Next
Sheets("NavigationPage").Activate
On Error GoTo 0
End With
Unload Me
Application.ScreenUpdating = True
End Sub

Help ??

Corey....
 
C

Corey

Now it is NOT working ???
The below code places valuies from the Sheet-"Data" into the Sheet-"Job card",
BUT, the Highlighted LINE value DOES NOT apear, WHY ??
Removing the 'On Error Resume Next' i get a Object Variable not set error.


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
UserForm2.Hide
With ActiveWorkbook.Worksheets("Job Card")
..Select
Dim rngFound As Range
' On Error Resume Next
With Worksheets("Data").Range("A:A")
Set rngFound = .Find(What:=UserForm2.ListBox1.Value, After:=.Range("A1"), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
Range("B2").Value = ListBox1.Value
Range("B6").Value = rngFound.Offset(0, 4).Value ' <===== Error here !!!
End With
' Preview worksheet to either Print of simply View
ActiveWindow.SelectedSheets.PrintPreview
' Clears all data that was brought in from sheet "InspectionData"
Dim c As Range
For Each c In Sheets("Job Card").UsedRange
If c.Locked = False Then
c.ClearContents
End If
Next
Sheets("NavigationPage").Activate
On Error GoTo 0
End With
Unload Me
Application.ScreenUpdating = True
End Sub

Help ??

Corey....
 
D

Dave Peterson

after you do the .find, you'll want to test to see if you actually found the
value

set rngfound = .find.....

if rngfound is nothing then
'what should happen, msgbox, exit sub, beep???
else
'do the real work
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top