Excel VBA to copy

My task is to create a search database in Excel with an input form. I need a macro to transfer data from the input form to the database sheet, shift the active cell down 1 row and copy only the values ​​(not formatting)

Every time I try to run a macro, I get an error while executing the code. I have no experience with VB or VBA; please tell me what's wrong with that.

Sheets("Database").Select       'Navigates to Database worksheet
If ActiveSheet.FilterMode Then
    ActiveSheet.ShowAllData
End If                          'Clears filters
Sheets("Entry Form").Select     'Navigates back to Entry Form worksheet

Range("E10:L10").Select           ' select date, period, and data
Selection.Copy
Sheets("datatable").Select      ' navigate to datatable tab
Range("A1").Select
Selection.End(xlDown).Select    ' ctrl-down to last occupied row,
ActiveCell.Offset(1, 0).Select  ' then one more to first blank row

Selection.PasteSpecial Paste:=xlPasteValues
'Pastes data as values only into the Database worksheet

Sheets("Entry Form").Select     'Navigates to Entry Form worksheet
Application.CutCopyMode = False 'clears copy data from clipboard
Range("E10, L10").Select
Selection.ClearContents         'Clears data from drop down selections

Range("E10").Select             'Returns selection back to Date entry box

It goes to the very bottom of the next page and gives error 1004.

+4
source share
1 answer

, A1, xlDown. A , . , .

With Sheets("Database")       'Primarily use Database worksheet
    If .FilterMode Then .ShowAllData
    With .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) 'look from bottom up then down 1 row
        'direct value transfer is faster than Copy, Paste Special, Values
        .Cells.Resize(1, 8) = Sheets("Entry Form").Range("E10:L10").Value
    End With
End With

With Sheets("Entry Form")     'Primarily use Entry Form worksheet
    .Range("E10:L10").ClearContents 'Clears data from drop down selections
    .Range("E10").Select            'Returns selection back to Date entry box
End With

With... End With statement, , . . Select Excel VBA macros , .

+1

Source: https://habr.com/ru/post/1599407/


All Articles