Hi... well I'm stuck. I'm hoping that someone can help me identify where I'm going wrong with the macro code I'm using...I'm working on a spreadsheet that tracks purchases. When the word "Data" is listed in Column B of sheet 1 (Instruments_Tr adeCalc), I want to have the values of four cells in the same row copied from Sheet1 (Instruments_Tr adeCalc) onto the next available row of Sheet2 (RecordPosition s). The cells contain a formula so I'm looking to copy the value, not the formula - not sure if this is even possible.
I've gotten part of the way there in that I think the code is close. It doesn't return an error, but no data is copied to the subsequent work sheet (the Message Box at the end even returns "0 rows of matching data have been copied.").
I can't get it to copy and paste the data. Can someone help?
Here's what I'm currently working with:
Sub SearchForString ()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim Counter As Integer
On Error GoTo Err_Execute
'Start search in row 3
LSearchRow = 3
'Start copying data to row 2 in RecordPositions (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow )).Value) > 0
With Sheets("Instrum ents_TradeCalc" )
'If value in column B = "Data", copy entire row to RecordPositions
If .Range("B" & LSearchRow) = "Data" Then
Counter = Counter + 1
'Select row in Instruments_Tra deCalc to copy and then Paste
.Range("B" & LSearchRow).Res ize(1, 10).Copy Destination:=Sh eets("RecordPos itions").Range( "B" & LCopyToRow)
'Move counter to next row
LCopyToRow = LCopyToRow + 1
End If
LSearchRow = LSearchRow + 1
End With
Wend
'Position on cell A3
Application.Cut CopyMode = False
Sheets("Instrum ents_TradeCalc" ).Select
Range("A3").Sel ect
MsgBox Counter & " rows of matching data have been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
I've gotten part of the way there in that I think the code is close. It doesn't return an error, but no data is copied to the subsequent work sheet (the Message Box at the end even returns "0 rows of matching data have been copied.").
I can't get it to copy and paste the data. Can someone help?
Here's what I'm currently working with:
Sub SearchForString ()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim Counter As Integer
On Error GoTo Err_Execute
'Start search in row 3
LSearchRow = 3
'Start copying data to row 2 in RecordPositions (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow )).Value) > 0
With Sheets("Instrum ents_TradeCalc" )
'If value in column B = "Data", copy entire row to RecordPositions
If .Range("B" & LSearchRow) = "Data" Then
Counter = Counter + 1
'Select row in Instruments_Tra deCalc to copy and then Paste
.Range("B" & LSearchRow).Res ize(1, 10).Copy Destination:=Sh eets("RecordPos itions").Range( "B" & LCopyToRow)
'Move counter to next row
LCopyToRow = LCopyToRow + 1
End If
LSearchRow = LSearchRow + 1
End With
Wend
'Position on cell A3
Application.Cut CopyMode = False
Sheets("Instrum ents_TradeCalc" ).Select
Range("A3").Sel ect
MsgBox Counter & " rows of matching data have been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
Comment