PDA

View Full Version : Search external file for a value then print each row of data found using VBA



znightshade
05-02-2015, 01:51 AM
So for example, I have an excel file containing the following data.Column A Column B Column C1 Andrea 200.002 Cassie 300.003 Isabelle 250.00I should make a program that would ask the user to locate the source file, input a value from column A then print the data from column A, B and C on a specific cell of a new spreadsheet. I'll be using VBA so the new spreadsheet would be just where I'm running VBA.So far, I've coded this Private Sub CommandButton1_Click()Set myFile = Application.FileDialog(msoFileDialogOpen)With myFile .Title = "Choose File" .AllowMultiSelect = False .Filters.Clear .Filters.Add "Excel Files", "*.xlsx" If .Show -1 ThenExit SubEnd IfFileSelected = .SelectedItems(1)End WithLabel2 = FileSelectedEnd SubPrivate Sub CommandButton2_Click()Dim Source As StringIf Label2 = "" ThenMsgBox "Please enter a source"ElseSource = Label2.Caption answer = MsgBox("Source Confirmed. Continue?", vbYesNo + vbQuestion) If answer = vbYes Then UserForm2.Show Else 'Do Nothing End If End IfEnd SubThat is for locating the file then proceeding to entering a value which is userform2.Private Sub CommandButton1_Click()If TextBox1.Text = "" Then MsgBox "Please enter an invoice number."Else If Not IsNumeric(TextBox1.Text) Then MsgBox "Please enter a valid INVOICE NUMBER." Else (THIS PART IS FOR THE LOCATING AND PASTING STUFF AND I HAVENT FIGURED OUT HOW TO DO IT YET) End IfEnd IfEnd SubAny leads on how I will start? Any kind of help would be much appreciated.