ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy Data into Database gives error (https://www.excelbanter.com/excel-programming/385997-copy-data-into-database-gives-error.html)

bactfarmer

Copy Data into Database gives error
 
I'm creating a macro to copy information entered into a form and
put it into a database. It works fine as long as the first row of
information is filled out in the database. If the no information has
been added to the database yet I get Run-Time Error 1004 Application
Defined or Object Defined Error. What can I change to correct this
from happening

Sheets("Form").Select
Range("A6:X20").Select
Selection.Copy
Sheets("Database").Select
Range("A10").Select
Selection.End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.End(xlDown).Select


Coza

Copy Data into Database gives error
 
maybe add a :
If Range("A6:X20").value <"" then
Selection.Copy
Sheets("Database").Select
Range("A10").Select
Selection.End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.End(xlDown).Select
else
msgbox "There is No Value in the range !!"
end if

"bactfarmer" wrote in message
ups.com...
I'm creating a macro to copy information entered into a form and
put it into a database. It works fine as long as the first row of
information is filled out in the database. If the no information has
been added to the database yet I get Run-Time Error 1004 Application
Defined or Object Defined Error. What can I change to correct this
from happening

Sheets("Form").Select
Range("A6:X20").Select
Selection.Copy
Sheets("Database").Select
Range("A10").Select
Selection.End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.End(xlDown).Select




Dave Peterson

Copy Data into Database gives error
 
Maybe you could start at the bottom of column A and go up to find the last used
cell in that row, then come down one row.

Dim RngToCopy as Range
Dim DestCell as range

with worksheets("form")
set rngtocopy = .range("a6:X20")
end with

with worksheets("Database")
set destcell = .cells(.rows.count,"A").end(xlup).offset(1,0)
end with

rngtocopy.copy _
destination:=destcell



bactfarmer wrote:

I'm creating a macro to copy information entered into a form and
put it into a database. It works fine as long as the first row of
information is filled out in the database. If the no information has
been added to the database yet I get Run-Time Error 1004 Application
Defined or Object Defined Error. What can I change to correct this
from happening

Sheets("Form").Select
Range("A6:X20").Select
Selection.Copy
Sheets("Database").Select
Range("A10").Select
Selection.End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.End(xlDown).Select


--

Dave Peterson


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com