Please assist with an alteration on my code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

@MAIT supplied a code for data entry from userform to worksheet where it would enter the data into the last row on my sheet.
On a new userform that i have just made i would like to use the same code in respect of entering the data from userform to worksheet BUT not in the last row.
As you can see from my code below it will be entered into Row 6
I am stuck with cleaning the code up for submitting to the worksheet.


The code i have is shown below.

Code:
Private Sub CommandButton1_Click()Dim i As Long
Dim x As Long
Dim ctrl As Control
Dim lastrow As Long
lastrow = ThisWorkbook.Worksheets("DATABASE").Cells(Rows.Count, 1).End(xlUp).Row
    


    
 With ThisWorkbook.Worksheets("DATABASE")
    .Cells(lastrow + 1, 1).Value = TextBox1.Text: TextBox1.Value = ""
    .Cells(lastrow + 1, 2).Value = TextBox2.Text: TextBox2.Value = ""
    .Cells(lastrow + 1, 3).Value = TextBox3.Text: TextBox3.Value = ""
    .Cells(lastrow + 1, 4).Value = TextBox4.Text: TextBox4.Value = ""
    .Cells(lastrow + 1, 5).Value = TextBox5.Text: TextBox5.Value = ""
    .Cells(lastrow + 1, 6).Value = TextBox6.Text: TextBox6.Value = ""
    .Cells(lastrow + 1, 7).Value = TextBox7.Text: TextBox7.Value = ""
    .Cells(lastrow + 1, 8).Value = TextBox8.Text: TextBox8.Value = ""
    .Cells(lastrow + 1, 9).Value = TextBox9.Text: TextBox9.Value = ""
    .Cells(lastrow + 1, 10).Value = TextBox10.Text: TextBox10.Value = ""
    .Cells(lastrow + 1, 11).Value = TextBox11.Text: TextBox11.Value = ""
    .Cells(lastrow + 1, 12).Value = TextBox12.Text: TextBox12.Value = ""
    .Cells(lastrow + 1, 13).Value = TextBox13.Text: TextBox13.Value = ""
    .Cells(lastrow + 1, 14).Value = TextBox14.Text: TextBox14.Value = ""
    .Cells(lastrow + 1, 15).Value = TextBox15.Text: TextBox15.Value = ""
    .Cells(lastrow + 1, 16).Value = TextBox16.Text: TextBox16.Value = ""
TextBox2.SetFocus
TextBox2.Value = Now
TextBox1 = Format(TextBox2.Value, "dd/mm/yyyy")
End Sub


Rows("6:6").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6").Select
Range("A6:Q6").Borders.LineStyle = xlContinuous
Range("A6:Q6").Borders.Weight = xlThin
Range("A6:Q6").Interior.ColorIndex = 6
Range("M6") = Date
Range("$Q$6").Value = "'NO NOTES FOR THIS CUSTOMER"
Range("$Q$6").HorizontalAlignment = xlCenter
Unload DatabaseInput
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,
The code at the end of the code supplied is where it is to be inserted"Row 6".

The advice i need is say
TextBox1 value to column 1
Then TextBox2 then 3,4,5 etc etc
 
Upvote 0
Hi,
Forgot to mention,
On my userform i have the following.
5 Text Boxes
12 Comboboxes

Thanks
 
Last edited:
Upvote 0
This will assist you.

Worksheet Column 1 User Form Text Box 1
Worksheet Column 2 User Form ComboBox 1
Worksheet Column 3 User Form ComboBox 2
Worksheet Column 4 User Form ComboBox 3
Worksheet Column 5 User Form ComboBox 4
Worksheet Column 6 User Form ComboBox 5
Worksheet Column 7 User Form ComboBox 6
Worksheet Column 8 User Form ComboBox 7
Worksheet Column 9 User Form ComboBox 8
Worksheet Column 10 User Form ComboBox 9
Worksheet Column 11 User Form ComboBox 10
Worksheet Column 12 User Form ComboBox 11
Worksheet Column 13 User Form Text Box 2
Worksheet Column 14 User Form ComboBox 12
Worksheet Column 15 User Form Text Box 3
Worksheet Column 16 User Form Text Box 4
Worksheet Column 17 User Form Text Box 5
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,553
Members
449,038
Latest member
Guest1337

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