ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Morning,
I have the code in use below but need some help / advice please.
The code works fine & how i wanted it,then i need to format the vales when i sent them from userform to worksheet.
So because of this i added the extra code shown in RED
It does work but this is where i need some help / advice.
1,
So far i can only work out how to apply it to a range, as opposed to the row at which the values are inserted to the worksheet, current ive set its range to N24:R24
2,
I need to also add to this code All Borders but cant seem to work that part out.
Other than that i think im sorted.
Please advise & have a nice day thanks.
I have the code in use below but need some help / advice please.
The code works fine & how i wanted it,then i need to format the vales when i sent them from userform to worksheet.
So because of this i added the extra code shown in RED
It does work but this is where i need some help / advice.
1,
So far i can only work out how to apply it to a range, as opposed to the row at which the values are inserted to the worksheet, current ive set its range to N24:R24
2,
I need to also add to this code All Borders but cant seem to work that part out.
Other than that i think im sorted.
Please advise & have a nice day thanks.
Rich (BB code):
Private Sub CommandButton1_Click()
Dim i As Long, x As Long
Dim LastRow As Long
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("G INCOME")
With Sheets("G INCOME")
If TextBox1.Value = "" Then
MsgBox "NO CUSTOMER'S NAME WAS ENTERED", vbCritical, "NAME & ADDRESS EMPTY MESSAGE"
TextBox1.SetFocus
Exit Sub
ElseIf TextBox2.Value = "" Then
MsgBox "NO ADDRESS WAS ENTERED", vbCritical, "NAME & ADDRESS EMPTY MESSAGE"
TextBox2.SetFocus
Exit Sub
ElseIf TextBox3.Value = "" Then
MsgBox "NO POST CODE WAS ENTERED", vbCritical, "NAME & ADDRESS EMPTY MESSAGE"
TextBox3.SetFocus
Exit Sub
ElseIf TextBox4.Value = "" Then
MsgBox "NO CHARGE WAS ENTERED", vbCritical, "NAME & ADDRESS EMPTY MESSAGE"
TextBox4.SetFocus
Exit Sub
ElseIf TextBox5.Value = "" Then
TextBox5.SetFocus
MsgBox "NO MILEAGE WAS ENTERED", vbCritical, "NAME & ADDRESS EMPTY MESSAGE"
Exit Sub
End If
With ThisWorkbook.Worksheets("G INCOME")
LastRow = .Cells(.Rows.Count, "N").End(xlUp).Row
With sh.Range("N24:R24")
.Font.Name = "Calibri"
.Font.Size = 16
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
.Cells(LastRow + 1, 14).Value = TextBox1.Text
.Cells(LastRow + 1, 15).Value = TextBox2.Text
.Cells(LastRow + 1, 16).Value = TextBox3.Text
.Cells(LastRow + 1, 17).Value = TextBox4.Text
.Cells(LastRow + 1, 18).Value = TextBox5.Text
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 4).End(xlUp).Row
.Range("N4:R" & x).Sort Key1:=Range("N4"), Order1:=xlAscending, Header:=xlGuess
Unload AddCustomer
MsgBox "DATABASE SUCCESSFULLY UPDATED", vbInformation, "GRASS INCOME NAME & ADDRESS MESSAGE"
End With
Range("N4").Select
End With
End Sub