Most often we would have the entire data in Excel and would require data corresponding to the cell value taken from the master sheet and populated in the current one dynamically.
In the following example the master sheet is named as "DB" and contains all records with the primary key being the first column.
Function Snippet_For_Copy(sSearchString)
If Trim(sSearchString) = "" Then Exit Function
With Sheets("DB").Columns("A:A")
Set rFindCell = .Find(sSearchString, LookIn:=xlValues, LookAt:=xlWhole)
If Not rFindCell Is Nothing Then
Sheets("DB").Rows(rFindCell.Row).EntireRow.Copy _
Destination:=Range("A" & ActiveCell.Row)
End If
End With
End Function
If the user enters a data in the first column of the current sheet, the above function will check the data in the DB sheet and transfer entire row if a match is found
You can trigger the function using Worksheet_SelectionChange event
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If IsNumeric(Target) = False Then Exit Sub
If Trim(Target) = "" Then Exit Sub
Application.EnableEvents = False
Snippet_For_Copy Target.Value
Application.EnableEvents = True
End Sub
0 comments:
Post a Comment