A Microsoft Office (Excel, Word) forum. OfficeFrustration

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 » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro to find value and then copy associated range



 
 
Thread Tools Display Modes
  #1  
Old December 31st, 2009, 03:39 PM posted to microsoft.public.excel.misc
hnyb1
external usenet poster
 
Posts: 27
Default Macro to find value and then copy associated range

Hi,

Using Excel 2003 I've tried to piece together a macro to find a cell in one
worksheet and the then set the range based on that found cell... copy and
paste to another worksheet. It's not quite working and I can't figure out
why. Any help would, once again, be greatly appreciated. Code is as follows

Sub addhatchinfo()
Worksheets("Hatchability Data").Activate

Dim FindWhat As String
Dim FoundCell As Range
Dim cpyrng As Range

FindWhat = InputBox("Enter the Tracking Number here")
Worksheets("Viability Data").Activate
'On Error Resume Next
Set FoundCell = Range("d:d").Find(what:=FindWhat, _
lookat:=xlPart, LookIn:=xlValues)
FoundCell.Activate
x = ActiveCell.Row
Set cpyrng = Range(Cells(x, "a"), Cells(x, "aj"))
Range(cpyrng).Select
Selection.Copy

Worksheets("Hatchability Data").Activate
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveCell.Paste
End Sub

Happy New Year to all!!
  #2  
Old December 31st, 2009, 04:09 PM posted to microsoft.public.excel.misc
Don Guillett
external usenet poster
 
Posts: 6,167
Default Macro to find value and then copy associated range

NO selections necessary. Fire from anwhere in the workbook
Sub copytrackingnum()
Set ss = Sheets("sheet4")
Set ds = Sheets("sheet3")
dlr = ds.Cells(Rows.Count, 1).End(xlUp).Row + 1
FindWhat = InputBox("Enter the Tracking Number here")

Set FoundCell = ss.Columns(4).Find(FindWhat, LookIn:=xlValues, _
lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundCell Is Nothing Then
'MsgBox FoundCell.Row
ss.Range(ss.Cells(FoundCell.Row, "a"), _
ss.Cells(FoundCell.Row, "aj")).Copy ds.Cells(dlr, 1)
End If
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"hnyb1" wrote in message
news
Hi,

Using Excel 2003 I've tried to piece together a macro to find a cell in
one
worksheet and the then set the range based on that found cell... copy and
paste to another worksheet. It's not quite working and I can't figure out
why. Any help would, once again, be greatly appreciated. Code is as
follows

Sub addhatchinfo()
Worksheets("Hatchability Data").Activate

Dim FindWhat As String
Dim FoundCell As Range
Dim cpyrng As Range

FindWhat = InputBox("Enter the Tracking Number here")
Worksheets("Viability Data").Activate
'On Error Resume Next
Set FoundCell = Range("d:d").Find(what:=FindWhat, _
lookat:=xlPart, LookIn:=xlValues)
FoundCell.Activate
x = ActiveCell.Row
Set cpyrng = Range(Cells(x, "a"), Cells(x, "aj"))
Range(cpyrng).Select
Selection.Copy

Worksheets("Hatchability Data").Activate
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveCell.Paste
End Sub

Happy New Year to all!!


 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:44 PM.


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