Copying Data From Closed Workbook Using Input Box to Search For Criteria

Smith369

New Member
Joined
Jul 25, 2016
Messages
7
Hello relatively new to using VBA & Macro's , i am trying to setup a macro that will prompt the user via input box to type a client name in , it will then search the closed workbook(Quick Test.xlsm)"Sheet 2" (Companies) for the client name and once found pull the entire row of data through to the open workbook(Test2.xlsm)"Sheet 1"(Master) and paste in the next available row(A5).

Below is the code i have started to create however i am not sure how to reference each workbook and which one to search in and where to paste to. At present when i click the button the code is attached to it just copies data from the current sheet:

Code:
Dim srcWorkbook As Workbook
Dim destWorkbook As Workbook
Dim srcWorksheet As Worksheet
Dim destWorksheet As Worksheet
Dim SearchRange As Range
Dim destPath As String
Dim destname As String
Dim destsheet As String
Set srcWorkbook = ActiveWorkbook
Set srcWorksheet = ActiveSheet
Dim vnt_Input As String


vnt_Input = Application.InputBox("Please Enter Client Name", "Client Name")


destPath = "C:\test\"
destname = "Test2.xlsm"
destsheet = "Sheet1"




Set destWorkbook = Workbooks(destname)
If Err.Number <> 0 Then
    Err.Clear
    Set wbTarget = Workbooks.Open(destPath & destname)
    CloseIt = True
End If


For Each c In Range("A2:W100")


If InStr(c, vnt_Input) > 0 Then


 c.EntireRow.Copy
    destWorkbook.Activate
    destWorkbook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    srcWorkbook.Activate
End If
Next

Thanks in advance i am sure the code is very simple, i have search on google and found similar posts regarding linking multiple workbooks but still cant seem to work it out.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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