*urgent help needed* copy data from one workbook to other workbook based on search value

shahnawazatiq

New Member
Joined
May 4, 2010
Messages
1
dear all,

i have one text box and a search (command) button in one excel workbook (search workbook) and my database is in other workbook (data workbook).my problem is that user has to write few words in text box provided in search workbook and press search button,on search button macro has been written to fetch data if it is found in data workbook.it should return those rows in the search workbook.kindly help me out
code written on search button is as follows .
****************************************
Private Sub Button2_Click()
Dim MyFiles As String
'code for open a workbook by shaan on 30-04-2010
' Specify a target directory
MyFiles = ActiveWorkbook.Path & "\*.xls"
'Open Workbooks one by one

Do While MyFiles <> ""
'Copy the Source Data
'Range("A1").Activate
If Sheet1.TextBox1.Text = "" Then
MsgBox ("Enter a search String")
Exit Sub
Workbooks.Open Filename:=MyFiles & "\RO_CIRCULARS.xls "
Workbooks.Open Filename:=MyFiles & "\excel_30apr.xls"
Else
Range("A1").Activate
If InStr(ActiveCell.Value, Sheet1.TextBox1.Text) Then
'Range(Selection, Selection.End(xlToLeft)).Select
'Range(Selection, Selection.End(xlDown)).Select
Range("A1:V400").Select
Selection.Copy
'Open the destination file

'Select next available row and paste copied data
Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Close and Save the destination file
ActiveWorkbook.Save
ActiveWindow.Close
'Close the source file without saving
Workbooks(ActiveWorkbook.Name).Close SaveChanges:=False
'Next File in the Directory
MyFiles = Dir()
End If
End If
Loop
End Sub
'Private Sub CommandButton1_Click()
'If TextBox1.Text = "" Then
' MsgBox ("Select a Ingredient !")
' Else
' ListBox1.Clear
' Range("b1").Activate
' Do While ActiveCell.Value <> ""
' If InStr(ActiveCell.Value, TextBox1.Text) Then _
' ListBox1.AddItem ActiveCell.Offset(0, -1).Value
' ActiveCell.Offset(1, 0).Activate
' Loop
' End If
'End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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