Overwrite the value if other cell is not blank

argandoz

New Member
Joined
Mar 5, 2009
Messages
13
Hi! Guys,

Anyone can help me find a formula for :

Column A (Plan Date) and Column B (Date Recieved) contain date value. If B2 is blank, A2 will maintain the date entered in it. However if B2 has date (either earlier or later than A2) it will supersede the date with the date value in B2.


Thanks.

Argandoz
 
I'd use the Change event rather than SelectionChange
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address = "$B$2" And Target.Value <> vbNullString Then
        Application.EnableEvents = False
        Target.Offset(0, -1).Value = Target.Value
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
This works great for two collumns but I am looking to use it for 6 columns can you creat similar code for that will step through the columns too?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Range("B" & Rows.Count).End(xlUp).Row
lastcolumn = Range("2" & Columns.Count).End(x1up).Column
For i = 2 To lastrow
For j = "B" To lastcolumn
If IsEmpty(Cells(i, j).Value) Then
Cells(i, 2).Value = Cells(i, 2).Value
Cells(i, "B").Value = Cells(i, "B").Value
Else
Cells(i, "B").Value = Cells(i, i).Value
Cells(i, 2).Value = Cells(i, j).Value
End If
Next i
Next j
End Sub

this is what I came up with but its giving me an error
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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