code to clear a cell

palaeontology

Active Member
Joined
May 12, 2017
Messages
444
Office Version
  1. 2016
Platform
  1. Windows
I use the following code to add a date into the first available cell in column S

Code:
Private Sub Skip_A_Student_Click()    Dim Cnt As Long
    Dim NxtRw As Long
    
    NxtRw = Cells(Rows.Count, "S").End(xlUp).Offset(1).Row
    Cnt = WorksheetFunction.Count(Range("S2:S" & NxtRw))
    Range("S" & NxtRw).Value = Date
End Sub

How could I adjust the code if I want to clear the lowest cell in column S that has a date in it ?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
if this is identifying the correct cell then
Range("S" & NxtRw).ClearContents

adjusting up or down with NxtRw +1 0r -1
 
Last edited:
Upvote 0
How could I adjust the code if I want to clear the lowest cell in column S that has a date in it ?
See if this macro does what you want...
Code:
Sub ClearFirstDateInColumnS()
  Dim R As Long
  For R = 1 To Cells(Rows.Count, "S").End(xlUp).Row
    If IsDate(Cells(R, "S").Text) Then
      Cells(R, "S").ClearContents
      Exit For
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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