PC Review


Reply
Thread Tools Rate Thread

Code Problems

 
 
=?Utf-8?B?TGVvbg==?=
Guest
Posts: n/a
 
      3rd Aug 2007
Hello

Im trying to make a code that will help me find information in a work sheet
like a search/find tool. I have got this far but now im stuck because it
never find any infomation.

I also need to know is there any way to make to it seach in one column
instead of the whole work sheet

here's my code:
Sub BatchLocate()

Label1:
Dim myRange As Range
Dim lastRow As Integer
Dim myNum As Long
Dim myAnswer As String
Dim myCheck As Boolean
Dim n As Integer
Dim k As Integer

Range("D8").Select
Set myRange = ActiveCell.CurrentRegion
lastRow = myRange.Rows.Count
myAnswer = InputBox("Enter Batch Number.")
myCheck = IsNumeric(myAnswer)
If myAnswer <> Empty Then
If myCheck = False Then
MsgBox " Please enter a valid batch Number"
GoTo Label1
Else
myNum = CLng(myAnswer)
End If
Else
Range("d2").Select
Exit Sub
End If

Range("d2").Value = myNum
n = 8

For k = 1 To lastRow
myRange.Cells(k).Select
If myRange.Cells(k).Value = myNum Then
Range("B" & n).Value = myNum
ActiveCell.Offset(0, -2).Copy.ActiveSheet.Cells(4, 2).Select.Paste
ActiveCell.Offset(0, 2).Copy.ActiveSheet.Cells(4, 3).Select.Paste
ActiveCell.Offset(0, 4).Copy.ActiveSheet.Cells(4, 4).Select.Paste
ActiveCell.Offset(0, 5).Copy.ActiveSheet.Cells(4, 5).Select.Paste
n = n + 1
End If
Next k
If n = 8 Then
MsgBox "Batch " & myNum & " was not found."
Else
Range("d2").Select
End If

End Sub

Any help would be great.

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      3rd Aug 2007
the best thing to do is step through the code and wattch what is happening by
looking at the worksheet. I suspect that the active region may give you
problems bexasue it sops a blank rows and columns.

1) Go to VBA a click any where in the macro.
2) Then press F8.
3) go to worksheet and see if code is doing performing the right instructions
4) go back to vbba and press F8 again.


You can also press F9 to set a break point and use F5 to run. Look and the
differentt option in the VBA menues for more help.

"Leon" wrote:

> Hello
>
> Im trying to make a code that will help me find information in a work sheet
> like a search/find tool. I have got this far but now im stuck because it
> never find any infomation.
>
> I also need to know is there any way to make to it seach in one column
> instead of the whole work sheet
>
> here's my code:
> Sub BatchLocate()
>
> Label1:
> Dim myRange As Range
> Dim lastRow As Integer
> Dim myNum As Long
> Dim myAnswer As String
> Dim myCheck As Boolean
> Dim n As Integer
> Dim k As Integer
>
> Range("D8").Select
> Set myRange = ActiveCell.CurrentRegion
> lastRow = myRange.Rows.Count
> myAnswer = InputBox("Enter Batch Number.")
> myCheck = IsNumeric(myAnswer)
> If myAnswer <> Empty Then
> If myCheck = False Then
> MsgBox " Please enter a valid batch Number"
> GoTo Label1
> Else
> myNum = CLng(myAnswer)
> End If
> Else
> Range("d2").Select
> Exit Sub
> End If
>
> Range("d2").Value = myNum
> n = 8
>
> For k = 1 To lastRow
> myRange.Cells(k).Select
> If myRange.Cells(k).Value = myNum Then
> Range("B" & n).Value = myNum
> ActiveCell.Offset(0, -2).Copy.ActiveSheet.Cells(4, 2).Select.Paste
> ActiveCell.Offset(0, 2).Copy.ActiveSheet.Cells(4, 3).Select.Paste
> ActiveCell.Offset(0, 4).Copy.ActiveSheet.Cells(4, 4).Select.Paste
> ActiveCell.Offset(0, 5).Copy.ActiveSheet.Cells(4, 5).Select.Paste
> n = n + 1
> End If
> Next k
> If n = 8 Then
> MsgBox "Batch " & myNum & " was not found."
> Else
> Range("d2").Select
> End If
>
> End Sub
>
> Any help would be great.
>
> Thanks

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would C++/CLI solve PInvoke problems that C# has in this situation? What is the advantages using C++/CLI then C# when PInvoking umanaged C++ Code. Major problems here. Mohamed Mansour Microsoft C# .NET 14 17th Dec 2007 02:42 AM
2 problems with code =?Utf-8?B?dGVycnkgdw==?= Microsoft Access Form Coding 3 24th Sep 2007 02:12 PM
Frontpage problems (strips out code) since installing IE7 problems =?Utf-8?B?YWxsYW5i?= Microsoft Frontpage 1 15th Jan 2007 12:26 PM
Problems dispalying code in code view =?Utf-8?B?TW9zaGVNbw==?= Microsoft Frontpage 3 24th Oct 2006 12:44 PM
Re: Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Microsoft Excel Programming 0 14th Sep 2004 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:18 AM.