Copying data from one sheet to another

fish0321

New Member
Joined
Sep 15, 2020
Messages
14
Office Version
  1. 2016
HI,

I am trying to create a tracker to tack events. I am having a bit of trouble copying data from the event page to the event database page. When I push the button on the event page, I would like to have the data transferred to to table in the event database to the next available row. I have included an example spreadsheet. Thanks for you help in advance.

Event Tracker.xlsm
HIJKLMNOPQRS
1 Event
2
3
4
5Date:1/1/2023test 1:abHrs:6
6
7test 2:mnTest 3:Liasion
8
9Comments:
10Thank You for your help, it much appreciated!
11
12
13
14
15
16Test 4 (a,b,c)
17MikeSteveSteveScott
18
19
20
21
22
Event
Cells with Data Validation
CellAllowCriteria
N5List=Data!$A$2:$A$6
Q5List=Data!$B$2:$B$11
K7List=Data!$C$2:$C$15
N7List=Data!$D$2:$D$10
L17:O17List=Data!$E$2:$E$20



Event Tracker.xlsm
ABCDEFGHIJ
1DateTest 1Test 2Test 3HrsTest 4Test 4aTest 4bTest 4cComments
2
3
4
5
6
7
8
Event Database
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,
Assuming that your Database is an Excel Table (not a range) then see if following will do what you want

Place code in your data entry form worksheet code page

VBA Code:
Private Sub CommandButton1_Click()
    Dim rngEntry            As Range, cell As Range
    Dim i                   As Long
    Dim arr()               As Variant
    Dim tbl                 As ListObject
    Dim NewRecord           As ListRow
  
    'data entry input range
    Set rngEntry = Me.Range("K8,N8,K10,N10,Q8,L20:O20,J13")
    'database table
    Set tbl = ThisWorkbook.Worksheets("Event Database").ListObjects(1)
  
    'check form not blank
    If Application.CountA(rngEntry) > 0 Then
      
        'size array
        ReDim arr(1 To rngEntry.Cells.Count)
      
        'add entry to array
        For Each cell In rngEntry.Cells
            i = i + 1
            arr(i) = cell.Value
        Next cell
      
        'Add New row to the table
        Set NewRecord = tbl.ListRows.Add(AlwaysInsert:=True)
        'post array to table
        NewRecord.Range(1).Resize(, UBound(arr)).Value = arr
      
        'clear entry form
        rngEntry.Value = ""
        'inform user
        MsgBox "New Record Saved To Database", 64, "New Record"
    End If
  
End Sub

24-01-2023.xls
ABCDEFGHIJ
1DateTest 1Test 2Test 3HrsTest 4Test 4aTest 4bTest 4cComments
201/01/2023abmnLiasion6MikeSteveSteveScottThank You for your help, it much appreciated!
Event Database


Change name of your commandbutton as required

Dave
 
Last edited:
Upvote 0
Hi,
Assuming that your Database is an Excel Table (not a range) then see if following will do what you want

Place code in your data entry form worksheet code page

VBA Code:
Private Sub CommandButton1_Click()
    Dim rngEntry            As Range, cell As Range
    Dim i                   As Long
    Dim arr()               As Variant
    Dim tbl                 As ListObject
    Dim NewRecord           As ListRow
 
    'data entry input range
    Set rngEntry = Me.Range("K8,N8,K10,N10,Q8,L20:O20,J13")
    'database table
    Set tbl = ThisWorkbook.Worksheets("Event Database").ListObjects(1)
 
    'check form not blank
    If Application.CountA(rngEntry) > 0 Then
     
        'size array
        ReDim arr(1 To rngEntry.Cells.Count)
     
        'add entry to array
        For Each cell In rngEntry.Cells
            i = i + 1
            arr(i) = cell.Value
        Next cell
     
        'Add New row to the table
        Set NewRecord = tbl.ListRows.Add(AlwaysInsert:=True)
        'post array to table
        NewRecord.Range(1).Resize(, UBound(arr)).Value = arr
     
        'clear entry form
        rngEntry.Value = ""
        'inform user
        MsgBox "New Record Saved To Database", 64, "New Record"
    End If
 
End Sub

24-01-2023.xls
ABCDEFGHIJ
1DateTest 1Test 2Test 3HrsTest 4Test 4aTest 4bTest 4cComments
201/01/2023abmnLiasion6MikeSteveSteveScottThank You for your help, it much appreciated!
Event Database


Change name of your commandbutton as required

Dave

Hi,
Assuming that your Database is an Excel Table (not a range) then see if following will do what you want

Place code in your data entry form worksheet code page

VBA Code:
Private Sub CommandButton1_Click()
    Dim rngEntry            As Range, cell As Range
    Dim i                   As Long
    Dim arr()               As Variant
    Dim tbl                 As ListObject
    Dim NewRecord           As ListRow
 
    'data entry input range
    Set rngEntry = Me.Range("K8,N8,K10,N10,Q8,L20:O20,J13")
    'database table
    Set tbl = ThisWorkbook.Worksheets("Event Database").ListObjects(1)
 
    'check form not blank
    If Application.CountA(rngEntry) > 0 Then
     
        'size array
        ReDim arr(1 To rngEntry.Cells.Count)
     
        'add entry to array
        For Each cell In rngEntry.Cells
            i = i + 1
            arr(i) = cell.Value
        Next cell
     
        'Add New row to the table
        Set NewRecord = tbl.ListRows.Add(AlwaysInsert:=True)
        'post array to table
        NewRecord.Range(1).Resize(, UBound(arr)).Value = arr
     
        'clear entry form
        rngEntry.Value = ""
        'inform user
        MsgBox "New Record Saved To Database", 64, "New Record"
    End If
 
End Sub

24-01-2023.xls
ABCDEFGHIJ
1DateTest 1Test 2Test 3HrsTest 4Test 4aTest 4bTest 4cComments
201/01/2023abmnLiasion6MikeSteveSteveScottThank You for your help, it much appreciated!
Event Database


Change name of your commandbutton as required

Dave
 
Upvote 0
Dave, it looks like I get an error " invalid use of Me keyword". I am running Excel 2016
 
Upvote 0
Dave, it looks like I get an error " invalid use of Me keyword". I am running Excel 2016
Dave,

I created a new command button in which i no longer get a Me.Range error; however, I now get a the following problem, and yes it is a table. to add more frustration to my project, how would I have the Event page fields clear once the data is transferred to the Event Database with a popup message stating data has been entered. Once again, Thanks for your help!
 

Attachments

  • zzzzzzz.png
    zzzzzzz.png
    79 KB · Views: 4
Upvote 0
Hi,
as stated, the code goes in your entry forms worksheet code page.
Solution clears the form once data is posted to the database & msgbox will display telling user record has been saved

VBA Code:
'clear entry form
        rngEntry.Value = ""
        'inform user
        MsgBox "New Record Saved To Database", 64, "New Record"

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,215,370
Messages
6,124,526
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top