Copy rows from one sheet to another based on value

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this code to copy one row of data which matches with your criteria.
Code:
Private Sub cmdSerachInfoBasedOnCriteriaCopyRowToAnotherSheet_Click()
 Dim UsrCriteria As Long 'if criteria is a string edit this accordingly
 Dim varCriteriaRowNum As Long
 Dim Src As Worksheet
 Dim Rpt As Worksheet
 Dim CopRng As Range
 Set Src = Sheets("Source")
 Set Rpt = Sheets("Report")
 Src.Select
 '''''''''''''''''''''' Pin Point Search begins ''''''''''''''''''''''''''''''''''''''''
 Dim rSrchCriteria As Range 'range to check whether Criteria is available
 Range("A1").Select 'Col A has Criteria in Src
 UsrCriteria = InputBox("Type the Criteria" & vbCrLf & _
   "to search :", "Criteria!")
 Set rSrchCriteria = Range("A:A").Find(UsrCriteria, , xlValues, xlWhole)
 'code below searches Citeria, only in the column specified above as Selected Range.
 If rSrchCriteria Is Nothing Then 'if Criteria is 38, & no record is matching, _
  then, 38 is not found.
  MsgBox "You typed: " & UsrCriteria & "." & vbCrLf & _
   "This is not FOUND." & vbCrLf & _
   "So, Nothing to copy!"
   Exit Sub
 Else 'rSrchCriteria Is Nothing 'if Criteria is 38, _
  record found may be 388. So, moving pointer to that record.
  With rSrchCriteria
   .Activate 'Pointer moved to that record.
  End With
  If Val(rSrchCriteria) <> Val(UsrCriteria) Then 'if User Criteria is 38, _
   Srch Criteria found may be 388. So, 38 is not found.
   MsgBox "You typed: " & UsrCriteria & "." & vbCrLf & _
   "This is not FOUND." & vbCrLf & _
   "So, Nothing to copy!"
   Exit Sub
  ElseIf Val(rSrchCriteria) = Val(UsrCriteria) Then 'if Criteria is 38 and _
   record found is 38, then 38 is found.
   varCriteriaRowNum = ActiveCell.Row 'Store Row Criteria
  End If 'Val(rSrchCriteria) <> Val(UsrCriteria)
 End If 'rSrchCriteria Is Nothing
  '''''''''''''''''''''' Pin Point Search ends ''''''''''''''''''''''''''''''''''''''''
  Rpt.Cells.ClearContents 'Erases all rows in Report Sheet. If you dont want to erase all rows, edit A2 given below. 
  Set CopRng = Src.Range("A" & Trim(Str(varCriteriaRowNum))).EntireRow
  CopRng.Copy Rpt.Range("A2") 'Copies the searched row in Report Sheet 'If you want to paste on a specific row, edit A2.
  Rpt.Select
End Sub
You have not mentioned whether you want to search some other criteria or not.
 
Last edited:
Upvote 0
What criteria ?
Where do we match the criteria ?
Which Sheet is the row copied to ?
The link doesn't really provide much to go on !!
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,121
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top