Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Private Sub CommandButton1_Click()
Dim FDate As Date
Dim Name As String
Dim Amount As Integer
Dim City As String
Dim mydata As Workbook
Worksheets("Form").Select
FDate = Range("J7")
Name = Range("J9")
Amount = Range("J11")
City = Range("J13")
Set mydata = Workbook.Open("E:\Data\Recieved Data.xlsx")
Worksheets("Data").Select
Worksheets("Data").Range("A1").Select
If Worksheets("Data").Range("A1").Offset(1, 0) <> "" Then
Worksheets("Data").Range("A1").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = FDate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Name
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Amount
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = City
mydata.Save
End Sub


What I have tried:

Private Sub CommandButton1_Click()
Dim FDate As Date
Dim Name As String
Dim Amount As Integer
Dim City As String
Dim mydata As Workbook
Worksheets("Form").Select
FDate = Range("J7")
Name = Range("J9")
Amount = Range("J11")
City = Range("J13")
Set mydata = Workbook.Open("E:\Data\Recieved Data.xlsx")
Worksheets("Data").Select
Worksheets("Data").Range("A1").Select
If Worksheets("Data").Range("A1").Offset(1, 0) <> "" Then
Worksheets("Data").Range("A1").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = FDate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Name
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Amount
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = City
mydata.Save
End Sub
Posted
Updated 26-Oct-18 0:05am
Comments
Leo Chapiro 26-Oct-18 6:06am    
Your question is incomplete: what error get you? What programming language are you using: VB.NET, VB6, VBA, VB Script? Have you tried to debug your code? Where exactly (row) occurs the error?

1 solution

A 424 error is "Object required" and the chances are that your data is not returning data where you expect it should. We don't have access to your data, or any idea what line the error is occurring on, so we can't really help you much, if at all.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need. (it could be an early Visual studio, or this could be VBA - we don't know)

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Member 13913124 26-Oct-18 6:57am    
set mydata= Workbooks.open("path")
i am getting error in this line
OriginalGriff 26-Oct-18 7:07am    
And? What exactly is "path" supposed to mean to an Open function?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900