ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the working code supplied below.
It works like this.
Userform opens & i add values in the textboxes.
Running the code then adds a new row with the values to my worksheet withing range specified & sorts A-Z in column N
My maximim range for these values are N4:S38 & currently row values are at row 35
I would like to see a Msgbox once row 38 has values.
Reason being the list gets out of control & just continues down the page & i now need to put a stop to it.
Can the existing code be edited so no new row will be added if N4:S38 has values in it
I am using the working code supplied below.
It works like this.
Userform opens & i add values in the textboxes.
Running the code then adds a new row with the values to my worksheet withing range specified & sorts A-Z in column N
My maximim range for these values are N4:S38 & currently row values are at row 35
I would like to see a Msgbox once row 38 has values.
Reason being the list gets out of control & just continues down the page & i now need to put a stop to it.
Can the existing code be edited so no new row will be added if N4:S38 has values in it
Rich (BB code):
Private Sub CommandButton1_Click()
Dim i As Integer
Dim LastRow As Long
Dim wsGIncome As Worksheet
Dim arr(1 To 5) As Variant
Dim Prompt As String
Set wsGIncome = ThisWorkbook.Worksheets("G INCOME")
For i = 1 To 5
Prompt = Choose(i, "CUSTOMERS'S NAME", "ADDRESS", "POST CODE", "CHARGE", "MILEAGE")
With Me.Controls("TextBox" & i)
If Len(.Value) = 0 Then
MsgBox "NO " & Prompt & " & WAS ENTERED", 16, Prompt & " EMPTY FIELD MESSAGE"
.SetFocus
Exit Sub
Else
If InStr(1, .Value, "£") = 1 Then
arr(i) = CCur(.Value)
ElseIf IsDate(.Value) Then
arr(i) = DateValue(.Value)
ElseIf IsNumeric(.Value) Then
arr(i) = Val(.Value)
Else
arr(i) = .Value
End If
End If
End With
Next i
Application.ScreenUpdating = False
With wsGIncome
LastRow = .Cells(.Rows.Count, "N").End(xlUp).Row + 1
With .Cells(LastRow, 14).Resize(, UBound(arr))
.Value = arr
.Font.Name = "Calibri"
.Font.Size = 11
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders.Weight = xlThin
.Interior.ColorIndex = 6
.Cells(1, 1).HorizontalAlignment = xlLeft
End With
.Range("N4").Select
End With
Unload Me
Application.ScreenUpdating = True
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("N1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("N4:S38")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
MsgBox "DATABASE SUCCESSFULLY UPDATED", vbInformation, "GRASS INCOME NAME & ADDRESS MESSAGE"
End With
End Sub