I wonder whether someone may be able to help me please.
@Doug Clancy on this site offered some very much appreciated guidance and solution (shown below), which clears cell content and where necessary shifts the rows up to fill those that are blank.
Sub DelRow()
Dim RangeToClear As Range
Dim msg As VbMsgBoxResult
Sheets("Input").Protect "handsoff", UserInterfaceOnly:=True
Application.EnableCancelKey = xlDisabled
Application.EnableEvents = False
msg = MsgBox("Are you sure you want to delete this row?", vbYesNo)
If msg = vbNo Then Exit Sub
With Selection
Application.Intersect(.Parent.Range("A:S"), .EntireRow).Interior.ColorIndex = xlNone
Application.Intersect(.Parent.Range("T:AE"), .EntireRow).Interior.ColorIndex = 42
On Error Resume Next
Set RangeToClear = Selection.SpecialCells(xlCellTypeConstants)
On Error GoTo 0 ' or previously defined error handler
If Not RangeToClear Is Nothing Then
RangeToClear.ClearContents
End If
ActiveSheet.Range("A7:AG400").Sort Key1:=Range("B7"), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.Intersect(.Parent.Range("C:AE"), .EntireRow).Locked = True
Application.Intersect(.Parent.Range("AG:AG"), .EntireRow).Locked = True
End With
Application.EnableEvents = True
End Sub
The code correctly works, but I have a slight problem, through no fault of @Doug Clancy, more a change in my requirements.
To guide users on which row they need to add new records to, I've set a text signal i.e. "Enter your name", which always appears on the first empty row, ready for the user to add a new record. Unfortunately, this value is also picked up on the sort, which is where my problem lies.
I've been trying for a few days now to come up with a solution whereby the 'Sort' function is removed from the above code, with the remaining functionality left intact. Unfortunately without any success.
Could someone please, please have a look at this and offer some guidance on how I can remove the sorting of the cells.
Many thanks and kind regards
After working on this over the last few days, I've put together the following solution: