vb code question

S

Stan

I have numeric data in column A which which I want to find and then copy each
row that contains this data in columns A-C. In other words if rows 6 through
21 contain the value 7760 then through VB code I want to copy the data in
rows 6-21 and columns A-C.
I took a stab at the code below but it's giving me a data mismatch error on
the first part.

I'm new to coding so any help you can provide would be greatly appreciated.
Many thanks!



Sub GetData()
Dim rng As Range
Set rng = Range("A:C").Find(What:=7760, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
ActiveCell.Select
ActiveCell.Offset(0, 3).Select

Dim LastCellInN As Range
With ActiveSheet
Set LastCellInN = .Cells(.Rows.Count, "N").End(xlUp)
.Range("A3").Formula = "=N3/" & LastCellInN.Address(0, 0)

End With
End Sub
 
J

JLGWhiz

This snippet will find the number and copy the data in
columns A thru C of the row where the number is found
and paste the three column to cells H20 thru J20. You only
need the first cell of the range you want to paste to, if
the rest of the range is blank and is sufficiently large
enough to receive the incoming data. I picked H20 arbitrarily
so you will need to change that.

Sub findNcopy()
Dim lastRow As Long, c As Range
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set myRange = ActiveSheet.Range("A2:A" & lastRow)
Set c = myRange.Find(7760, LookIn:=xlValues)
If Not c Is Nothing Then
Range("A" & c.Row & ":C" & c.Row).Copy Range("H20") 'Change dest.
End If
End Sub

I did not know what the rest of the code you wrote was for
so I left it out. While this won't solve all the problem, maybe it will
help to point you in the right direction.
 

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