View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Help With VBA Copy Code

Change

Sheets(copyfromname).Rows(CStr(LSearchRow) & ":" &
CStr(LSearchRow)).Select
Selection.Copy


To

With Sheets(copyfromname)
Intersect(.Rows(LSearchRow), .Range("A:P")).Copy
End With

Also is this the best code to use or is there some other code I can
use? Help would be greatly appreciated!


You could simply filter the table to show the desired value in the key
column, and then copy the visible cells, so no looping would be involved,
and it would be LOTS faster. But a lot depends on your table structure - do
you know where the table is, which column has the values, is column A
filled, are there blank rows or columns, etc.

Also, you should get into the habit of

Dim LSearchRow As Long ' NOT Integer - your variable name starts with L
which usually implies Long....

Bernie

"CribbsStyle" wrote in message
...
Im using this vba code to copy each row that has a certain value in it
to another sheet. What I want to know is how can I get it to not copy
and paste the entire row, just A through P, like A3:P3.?

I call it by using this..

copyplayer "HidRatings", "PR Current", "12", "RB", "C", "2"


Sub copyplayer(ByVal copyfromname, copytoname, copytorow, position,
columnsearch, StartRow)
Application.ScreenUpdating = False
Dim LSearchRow As Integer
Dim LCopyToRow As Integer

LSearchRow = StartRow
LCopyToRow = copytorow

Sheets(copyfromname).Select
While Len(Range(columnsearch & CStr(LSearchRow)).Value) 0
If Range(columnsearch & CStr(LSearchRow)).Value = position Then
Sheets(copyfromname).Rows(CStr(LSearchRow) & ":" &
CStr(LSearchRow)).Select
Selection.Copy

Sheets(copytoname).Select
Sheets(copytoname).Range(CStr(LCopyToRow) & ":" &
CStr(LCopyToRow)).PasteSpecial xlPasteValues
LCopyToRow = LCopyToRow + 1
Sheets(copyfromname).Select

End If

LSearchRow = LSearchRow + 1

Wend

Exit Sub

End Sub

Also is this the best code to use or is there some other code I can
use? Help would be greatly appreciated!