bmba007
12-06-2019, 06:14 AM
I have a excel workbook with 2 text boxes where I basically put the file to copy data from and another to copy data to.
Below is my code:
Private Sub copydata_Click() Workbooks.Open Filename:=TextBox1.Text
Workbooks.Open Filename:=TextBox2.Text
Windows("f_database.xlsx").Activate
'Range("A1").Select
Cells.Find(What:="ID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("data_output.xlsx").Activate
Range("I17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("f_database.xlsx").Activate
Range("A1").Select
Cells.Find(What:="Address", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("data_output.xlsx").Activate
Range("A17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
MsgBox "Done!"
End Sub
When I run the code using a button, I'm getting the error
Run-time error '1004'
Application-defined or object-defined error in the line that I commented in my above code.
But now after commenting the previous error line I'm getting
Run-time error '91'
Object variable or With block variable not set
Can anybody help...!!
Below is my code:
Private Sub copydata_Click() Workbooks.Open Filename:=TextBox1.Text
Workbooks.Open Filename:=TextBox2.Text
Windows("f_database.xlsx").Activate
'Range("A1").Select
Cells.Find(What:="ID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("data_output.xlsx").Activate
Range("I17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("f_database.xlsx").Activate
Range("A1").Select
Cells.Find(What:="Address", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("data_output.xlsx").Activate
Range("A17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
MsgBox "Done!"
End Sub
When I run the code using a button, I'm getting the error
Run-time error '1004'
Application-defined or object-defined error in the line that I commented in my above code.
But now after commenting the previous error line I'm getting
Run-time error '91'
Object variable or With block variable not set
Can anybody help...!!