+ Reply to Thread
Results 1 to 5 of 5

Command button to insert data onto worksheet

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Command button to insert data onto worksheet

    I would like to use a command button to submit data input into a userform to a worksheet depending on what option is selected from a listbox. I have two worksheets one named "Linux" the other "Microsoft". When an OS is selected related to one or the other the data input in the userform will be inserted into the appropriate worksheet upon clicking on command button.


    Currently used code:
    Private Sub cmdAddNewHostMS_Click()

    Dim lrow As Long
    Dim wb As Workbook
    Dim wsl As Worksheet
    Dim wsm As Worksheet
    Set wb = ThisWorkbook
    Set wsm = Worksheets("Microsoft")
    Set wsl = Worksheets("Linux")

    'find empty row on Microsoft worksheet
    lrow = wsm.Range("A1").CurrentRegion.Rows.Count
    With wsm.Range("A1")

    'insert data into worksheet
    .Offset(lrow, 2) = Me.txtServerFunction.Value
    .Offset(lrow, 14) = Me.txtDataCenter.Value
    .Offset(lrow, 5) = Me.lstOperatingSystem.Value
    .Offset(lrow, 11) = Me.txtAppsInstalled.Value
    .Offset(lrow, 6) = Me.txtVirtualRam.Value * 1.5
    .Offset(lrow, 19) = Me.txtVirtualCPU.Value
    .Offset(lrow, 20) = Me.txtVirtualRam.Value
    .Offset(lrow, 23) = Me.txtOSVolume.Value
    .Offset(lrow, 27) = Me.txtBronzeTier.Value
    .Offset(lrow, 31) = Me.txtSilverTier.Value
    .Offset(lrow, 35) = Me.txtLogsTier.Value
    .Offset(lrow, 39) = Me.txtGoldTier.Value
    .Offset(lrow, 21) = Format(CDbl(txtOSVolume.Value) + CDbl(txtBronzeTier.Value) + CDbl(txtSilverTier.Value) + CDbl(txtLogsTier.Value) + CDbl(txtGoldTier.Value))

    End With

    Unload Me
    frmSrvInfo.Show

    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Command button to insert data onto worksheet

    Hi, jlwiii34,

    please use code-tags when displaying your code here for the ease of readability.

    Maybe give this code a try:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Command button to insert data onto worksheet

    Mostly works the way I am looking for (did not include code for adding data to linux sheet). my issue now is only copying data entered for Microsoft to "Microsoft" sheet and linux data to "Linux" sheet. The following code should input the data to the Linux work sheet leaving the Microsoft data blank and worksheet alone.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-16-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Command button to insert data onto worksheet

    Ok, using the following code I am trying to send data input on a userform to a particular worksheet based on what listbox selection is made. I am getting an error saying the "Object doesn't support this property or method" on the code "If ws = "Microsoft" Then". Is there any suggestion on how to fix this error?

    Please Login or Register  to view this content.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Command button to insert data onto worksheet

    Hi, jlwiii34,

    ws is set to show a worksheet, and that worksheet will most definitely have a name to which you may refer like
    Please Login or Register  to view this content.
    And maybe you could use InStr to check whether Windows Server or Linux are part of the selection to set a worksheet.

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1