Changing a userform to fill fixed cells

georgefreight

New Member
Joined
Sep 21, 2015
Messages
15
Hi

I've been adapting a userform I found online, however it is based on creating and filling in a new row each time. I need to change it so it always fills in the same cells then I have another macro to save it as a pdf to send to the customer.

Just trying to make it nice and simple so there is continuity in what is filled out and sent.
In trying to change it I've created errors which hasen't helped. The full code is below but I believe the problem are these 2 lines
Set ws = Worksheets("Sheet1")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

I wanted to set irow to be fixed as C4 and then I believe the rest of the code should fill in the cells appropriately from there (fingers crossed!)

Any and all help appreciated

Code:
Private Sub cmdAdd_Click()
    'Copy input values to sheet.
    Dim lRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

    With ws
        .Cells(1, 1).Value = Me.txtcompany.Value
        .Cells(2, 1).Value = Me.txtcountry.Value
        .Cells(3, 1).Value = Me.txtport.Value
        .Cells(4, 1).Value = Me.txtterms.Value
        .Cells(9, 5).Value = Me.txtsize.Value
        .Cells(27, 5).Value = Me.txtcost.Value
        .Cells(28, 5).Value = Me.txtline.Value
        .Cells(31, 5).Value = Me.txtfreq.Value
    End With
    'Clear input controls.
    Me.txtcompany.Value = ""
    Me.txtcountry.Value = ""
    Me.txtport.Value = ""
    Me.txtterms.Value = ""
    Me.txtsize.Value = ""
    Me.txtcost.Value = "£"
    Me.txtline.Value = ""
    Me.txtfreq.Value = ""
 End Sub
   
Private Sub CmdClose_Click()
    'Close UserForm.
    Unload Me
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this:
Code:
Private Sub cmdAdd_Click()
    'Copy input values to sheet.
    
        Cells(1, 1).Value = Me.txtcompany.Value
        Cells(2, 1).Value = Me.txtcountry.Value
        Cells(3, 1).Value = Me.txtport.Value
        Cells(4, 1).Value = Me.txtterms.Value
        Cells(9, 5).Value = Me.txtsize.Value
        Cells(27, 5).Value = Me.txtcost.Value
        Cells(28, 5).Value = Me.txtline.Value
        Cells(31, 5).Value = Me.txtfreq.Value
    End Sub
   
Private Sub CmdClose_Click()
    'Close UserForm.
    Unload Me
 
Upvote 0
Well that seems far simpler and cleaner. Just adjusted it over as it all runs down column C & G.

Thank you for your help.
 
Upvote 0
When you see:
Cells(2, 1).Value = Me.txtcountry.Value

This means row (2) Column (1)
So this script is putting the text into columns 1 and 5 or what you may refer to as "A" and "E"
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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