Transfer Data from Userform into first empty row of a table

MrsInspiration

New Member
Joined
Jan 18, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello, anyone, I've been working on this for about 3 days.
I have a user form that I created that contains all of the information for a project record, except the unique ID (which is in column A). I cannot figure out how to get the information from the user form into the first empty row of the table. I've read the thread "Userform entering data in the last row instead of the first empty row from top" However, my table data doesn't start until A4. I know almost nothing about VBA and I've tried copying and reading different Macros and can't customize the one I need. Here is the attachment.

PROJECT MANAGEMENT DATABASE DESIGN-CHRIS SANDERS-original w FORM Experiment.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
1 Master_File_IDProject No.InitiatorPRFAIM NoProject NameProject ManagerProject Manager IDCPSMDesignInterior DesignConstructionAssigned Resource IDCatagoryPriorityPhaseBldg No.Bldg NameOwnerStakeholder(1)Stakeholder(2)Funding SourceBORGTFIFY StartFY CompletionSCLTPBCommentsAttachments
2 On Agenda1/1/20211/2/2021$ value to be entered$ value to be entered
3
4
Sheet1
Cell Formulas
RangeFormula
A2A2=IF(F2<>"",CONCAT("000",1)," ")
A3A3=IF(F3<>"",CONCAT("000",$A2+1)," ")


Here are the two VBA I'm trying to use:
VBA Code:
Private Sub Submit_Click()

Dim ProjectNo As String
Dim Initiator As String
Dim PRF As String
Dim AIMNo As String
Dim PROJECTNAME As String
Dim ProjectManager As String
Dim ProjectManagerID As String
Dim CPSM As String
Dim Design As String
Dim InteriorDesign As String
Dim Construction As String
Dim Catagory As String
Dim Priority As String
Dim Phase As String
Dim BldgNo As String
Dim BldgName As String
Dim Owner As String
Dim Stake1 As String
Dim Stake2 As String
Dim FundingSource As String
Dim BOR As String
Dim GTFI As String
Dim FYSTART As String
Dim FYCOMPLETION As String
Dim SCL As String
Dim TPB As String
Dim Comments As String

ProjectNo = ProjectNumText.Text
Initiator = InitiatorText.Text
PRF = PRFText.Text
AIMNo = AIMText.Text
PROJECTNAME = PROJECTNAMETEXT.Text
ProjectManager = ProjectManagerCombo.Text
CPSM = CPSMCombo.Text
Design = DesignCombo.Text
InteriorDesign = iDesignCombo.Text
Construction = ConstructCombo.Text
Catagory = CategoryCombo.Text
Priority = PriorityCombo.Text
Phase = PhaseCombo.Text
BldgNo = BldgNumCombo.Text
Owner = OwnerCombo.Text
Stake1 = Stake1Combo.Text
Stake2 = Stake2Combo.Text
FundingSource = FundingText.Text
BOR = BORCombo.Text
GTFI = GTFICombo.Text
FYSTART = StartText.Text
FYCOMPLETION = CompleteText.Text
SCL = SLCText.Text
TPB = TPBText.Text
Comments = CommentsText.Text

Dim ws As Worksheet
Dim tbl As ListObject
Dim r As Range
Set ws = Worksheets("Master Project Data Source").ActiveSheet
Set tbl = ws.ListObjects("MasterProjectTable")
'For r = 
'Some kind of For Loop that I can't get working
'Dim newRow As ListRow
'Set newRow = tbl.ListRows.Add
'With newRow
 '   .Range(1).Value = Me.PROJECTNAMETEXT.Value
 '   .Range(2) = Initiator
'    .Range(3) = PRF
 '   .Range(4) = AIMNo
 '   .Range(5) = PROJECTNAME
 '   .Range(6) = ProjectManager
'    .Range(7) = CPSM
'    .Range(8) = Design
'    .Range(9) = InteriorDesign
 '   .Range(10) = Construction
 '   .Range(11) = Catagory
'    .Range(12) = Priority
  '  .Range(13) = Phase
 '   .Range(14) = BldgNo
'    .Range(15) = Owner
'    .Range(16) = Stake1
'    .Range(17) = Stake2
 '   .Range(18) = FundingSource
'    .Range(19) = BOR
 '   .Range(20) = GTFI
 '   .Range(21) = FYSTART
 '   .Range(22) = FYCOMPLETION
 '   .Range(23) = SCL
  '  .Range(24) = TPB
 '   .Range(25) = Comments
End With

End Sub
Any help would be appreciated
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi
welcome to forum

Glancing at your code, you should not need all those variables to post data from userform to worksheet but the part of your code you have commented out looks like you are going in right direction.

Not tested but see if this update to code helps

VBA Code:
Private Sub Submit_Click()
    Dim ws          As Worksheet
    Dim newRow      As ListRow
    Dim tbl         As ListObject
    

    Set ws = Worksheets("Master Project Data Source")
    Set tbl = ws.ListObjects("MasterProjectTable")
    
    'Add New Row At Bottom of Table
    Set newRow = tbl.ListRows.Add(AlwaysInsert:=True)
    
    With newRow
    'master file ID
        With .Range(1)
            .Formula = "=IF([@[Project Name]]<>"""",ROW()-ROW(" & tbl.Name & "[#Headers]),"""")"
            .NumberFormat = "0000"
        End With
        
        .Range(2) = Me.ProjectNumText.Text
        .Range(3) = Me.InitiatorText.Value
        .Range(4) = Me.PRFText.Value
        .Range(5) = Me.AIMNoText.Value
        .Range(6) = Me.PROJECTNAMEText.Value
        .Range(7) = Me.ProjectManagerCombo.Text
        .Range(9) = Me.CPSMCombo.Text
        .Range(10) = Me.DesignCombo.Text
        .Range(11) = Me.iDesignCombo.Text
        .Range(12) = Me.ConstructCombo.Text
        '.Range(13) =  AssignedResourceID < control name not shown??
        .Range(14) = Me.CategoryCombo.Text
        .Range(15) = Me.PriorityCombo.Text
        .Range(16) = Me.PhaseCombo.Text
        .Range(17) = Me.BldgNumCombo.Text
        .Range(19) = Me.OwnerCombo.Text
        .Range(20) = Me.Stake1Combo.Text
        .Range(21) = Me.Stake2Combo.Text
        .Range(22) = Me.FundingText.Text
        .Range(23) = Me.BORCombo.Text
        .Range(24) = Me.GTFICombo.Text
        .Range(25) = Me.StartText.Text
        .Range(26) = Me.CompleteText.Text
        .Range(27) = Me.SLCText.Text
        .Range(28) = Me.TPBText.Text
        .Range(29) = Me.CommentsText.Text
    
    End With
    
End Sub

Hopefully, update will assist you.

Dave
 
Upvote 0
Hi
welcome to forum

Glancing at your code, you should not need all those variables to post data from userform to worksheet but the part of your code you have commented out looks like you are going in right direction.

Not tested but see if this update to code helps

VBA Code:
Private Sub Submit_Click()
    Dim ws          As Worksheet
    Dim newRow      As ListRow
    Dim tbl         As ListObject
   

    Set ws = Worksheets("Master Project Data Source")
    Set tbl = ws.ListObjects("MasterProjectTable")
   
    'Add New Row At Bottom of Table
    Set newRow = tbl.ListRows.Add(AlwaysInsert:=True)
   
    With newRow
    'master file ID
        With .Range(1)
            .Formula = "=IF([@[Project Name]]<>"""",ROW()-ROW(" & tbl.Name & "[#Headers]),"""")"
            .NumberFormat = "0000"
        End With
       
        .Range(2) = Me.ProjectNumText.Text
        .Range(3) = Me.InitiatorText.Value
        .Range(4) = Me.PRFText.Value
        .Range(5) = Me.AIMNoText.Value
        .Range(6) = Me.PROJECTNAMEText.Value
        .Range(7) = Me.ProjectManagerCombo.Text
        .Range(9) = Me.CPSMCombo.Text
        .Range(10) = Me.DesignCombo.Text
        .Range(11) = Me.iDesignCombo.Text
        .Range(12) = Me.ConstructCombo.Text
        '.Range(13) =  AssignedResourceID < control name not shown??
        .Range(14) = Me.CategoryCombo.Text
        .Range(15) = Me.PriorityCombo.Text
        .Range(16) = Me.PhaseCombo.Text
        .Range(17) = Me.BldgNumCombo.Text
        .Range(19) = Me.OwnerCombo.Text
        .Range(20) = Me.Stake1Combo.Text
        .Range(21) = Me.Stake2Combo.Text
        .Range(22) = Me.FundingText.Text
        .Range(23) = Me.BORCombo.Text
        .Range(24) = Me.GTFICombo.Text
        .Range(25) = Me.StartText.Text
        .Range(26) = Me.CompleteText.Text
        .Range(27) = Me.SLCText.Text
        .Range(28) = Me.TPBText.Text
        .Range(29) = Me.CommentsText.Text
   
    End With
   
End Sub

Hopefully, update will assist you.

Dave
Dave, it worked like a charm. Thank you for the quick reply.
 
Upvote 0
welcome glad update resolved for you & appreciate feedback

Dave
Last little thing...Do you have any recommendations for where I can do some online learning for VBA or other coding that would help me with Excel?
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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