Check cell before replacing

GWHarvey

New Member
Joined
Feb 6, 2019
Messages
6
I am checking a cell and if it is true then copy that row toanother spreadsheet, then I insert a date to another column which all worksgreat. What I would like to do now is check to see if there is already a datein that column, if blank then add it


This is the code that works:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Columns(12)) Is Nothing Then
IfUCase(Target.Value) = "R" Then
Range("A" & Target.Row).Resize(1, 45).CopySheets("Precalc").Cells(Rows.Count, 1).End(xlUp)(2)
Target.EntireRow.Delete
Sheets("Precalc").Cells(Rows.Count, 12).End(xlUp).Offset(, 1)= Date
End If
End If
End Sub

I don’t know how to program the address to check the date(might be easier to change the date before copying to another sheet?)

If UCase(Target.Value) = "R" Then
Range("A" & Target.Row).Resize(1, 45).CopySheets("Precalc").Cells(Rows.Count, 1).End(xlUp)(2)
Target.EntireRow.Delete
If Target.Row,column 13 <> blank then
Sheets("Precalc").Cells(Rows.Count, 12).End(xlUp).Offset(, 1)= Date
End If
End If


Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try with this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Columns(12)) Is Nothing Then
        If UCase(Target.Value) = "R" Then
            Range("A" & Target.Row).Resize(1, 45).Copy Sheets("Precalc").Cells(Rows.Count, 1).End(xlUp)(2)
            If Cells(Target.Row, 13).Value = "" Then
                Sheets("Precalc").Cells(Rows.Count, 12).End(xlUp).Offset(, 1) = Date
            End If
            Target.EntireRow.Delete
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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