The VBA as seems to be glitchy (screen view jumps back and forth) and does not end back on the userform. Is there a way to refine the VBA to work better? and is there another way to place the row in a specific row on a worksheet?
Excel VBA - using userform and datasheet (workbook A). After inputting a number in up to 8 different textboxes on a userform. The textbox is linked to a datasheet. the vba gets the number from the datasheet and searches another workbook (Workbook B) for the number in Column A. After found it will copy and paste to a row on the sheet on (workbook a). the sequence will continue for the next textbox and the next etc.
Private Sub CommandButton83_Click()
Dim LastRow As Integer, i As Integer, erow As Integer
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox192.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(3, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
Workbooks("Workbook2").Worksheets("Roll Call").Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox193.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(5, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
Workbooks("Workbook2").Worksheets("Roll Call").Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox194.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(7, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
Workbooks("Workbook2").Worksheets("Roll Call").Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox195.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:\location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(9, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox196.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:Location of file"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(11, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox197.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:Location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(13, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox198.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(15, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
If OptionButton65.Value = True Then
Workbooks("Workbook2").Worksheets("Roll Call").Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value = TextBox199.Value Then
Range(Cells(i, 1), Cells(i, 25)).Select
Selection.Copy
Workbooks.Open Filename:="C:location"
Workbooks("MainWorkBook").Worksheets("PatientData").Activate
Worksheets("PatientData").Select
ActiveSheet.Cells(17, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
Application.CutCopyMode = False
End If
Next i
End Sub
'Being able to refine the VBA to single function of looking for number provided in a textbox (which will change on every use) on a closed/open workbook and copy the row that matches the number onto the userform workbook in a specific row. Only as many as eight rows will be copied per use but mor than likely three will be used. So not all textboxes will have data entered every time.