A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA find



 
 
Thread Tools Display Modes
  #1  
Old May 7th 12, 01:10 PM
m5u4r3p2h1y m5u4r3p2h1y is offline
Junior Member
 
First recorded activity by ExcelBanter: May 2012
Posts: 4
Default VBA find

Hi everyone.
Wondering if any one can help. The following code below is used in a large excel spreadsheet with a ton of numbers. in the top row (1) are reference numbers which at this preliminary stage in my coding I am just trying to find. (the reference numbers are in the sheet like this ex. 100,040 I hope the comma is not a big deal)

Code:
Sub ref()

Dim RefNumber As Long
Dim RefFound As Range
RefNumber = Application.InputBox("Reference #", "Meter Point Reference_ Number", , , , , , 4)

Set RefFound = Cells.Find(what:=RefNumber, *REALLY DONT KNOW WHAT_ TO PUT HERE", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,_ SearchDirection:=xlNext)

MsgBox "Found Reference # at column" & RefFound.Column

End Sub

I had gotten it to run but for every reference number I tried it gave me a column of 238 (even when i changed the reference number to a different corresponding column). Any help would be greatly appreciated.

[For those wondering my goal is: find reference number, find last row with data in the column, copy range, paste into new sheet.]
  #2  
Old May 7th 12, 03:50 PM
m5u4r3p2h1y m5u4r3p2h1y is offline
Junior Member
 
First recorded activity by ExcelBanter: May 2012
Posts: 4
Default

Quote:
Originally Posted by m5u4r3p2h1y View Post
Hi everyone.
Wondering if any one can help. The following code below is used in a large excel spreadsheet with a ton of numbers. in the top row (1) are reference numbers which at this preliminary stage in my coding I am just trying to find. (the reference numbers are in the sheet like this ex. 100,040 I hope the comma is not a big deal)

Code:
Sub ref()

Dim RefNumber As Long
Dim RefFound As Range
RefNumber = Application.InputBox("Reference #", "Meter Point Reference_ Number", , , , , , 4)

Set RefFound = Cells.Find(what:=RefNumber, *REALLY DONT KNOW WHAT_ TO PUT HERE", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,_ SearchDirection:=xlNext)

MsgBox "Found Reference # at column" & RefFound.Column

End Sub

I had gotten it to run but for every reference number I tried it gave me a column of 238 (even when i changed the reference number to a different corresponding column). Any help would be greatly appreciated.

[For those wondering my goal is: find reference number, find last row with data in the column, copy range, paste into new sheet.]
New Problem:

code:
Sub ref()

Dim RefNumber As Long
Dim RefFound As Range
Dim LastRow As Long

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

RefNumber = Application.InputBox("Reference #", "Meter Point Reference Number", , , , , , 4)

Range("A1").EntireRow.Select
Selection.Find("RefNumber", ActiveCell, xlValues, xlyColumns, xlNext).Activate

'Set RefFound = Cells.Find(RefNumber, , xlValues, xlPart, xlByRows, xlNext)

'MsgBox "Found Reference # at column" & RefFound.Column

MsgBox "Found Ref # at column" & ActiveCell.Column

End Sub

This is giving me a run time error 9 and I am not sure why.

The example value in cell(M1) has in the cell 100,040
I input into the InputBox 100040 and it gives me the error. Any ideas?
  #3  
Old May 7th 12, 06:07 PM posted to microsoft.public.excel.programming
GS[_2_]
external usenet poster
 
Posts: 2,276
Default VBA find

m5u4r3p2h1y wrote :
> Hi everyone.
> Wondering if any one can help. The following code below is used in a
> large excel spreadsheet with a ton of numbers. in the top row (1) are
> reference numbers which at this preliminary stage in my coding I am just
> trying to find. (the reference numbers are in the sheet like this ex.
> 100,040 I hope the comma is not a big deal)
>
> Code:
> Sub ref()
>
> Dim RefNumber As Long
> Dim RefFound As Range
> RefNumber = Application.InputBox("Reference #", "Meter Point Reference_
> Number", , , , , , 4)
>
> Set RefFound = Cells.Find(what:=RefNumber, *REALLY DONT KNOW WHAT_ TO
> PUT HERE", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,_
> SearchDirection:=xlNext)
>
> MsgBox "Found Reference # at column" & RefFound.Column
>
> End Sub
>
> I had gotten it to run but for every reference number I tried it gave me
> a column of 238 (even when i changed the reference number to a different
> corresponding column). Any help would be greatly appreciated.
>
> [For those wondering my goal is: find reference number, find last row
> with data in the column, copy range, paste into new sheet.]


You might want to change SearchOrder to search by columns, and LookAt
might be better as 'xlWhole'. Don't enter the comma in the input box if
it's there due to number formatting.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace - delete the remainder of the text in the cell after my Find [email protected] Excel Programming 4 August 4th 07 03:39 AM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
find and delete text, find a 10-digit number and put it in a textbox Paul Excel Programming 3 November 16th 04 04:21 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 01:42 PM.


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