VBA Date in column Isuue

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
I though the code in red was working and for its part it does do the job, but not as I expected. The code in red puts todays date into column A if there is DATA in column B. The code was fine yesterday but not today.

[CODE
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
' Copy from Sheet2 to Sheet1
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Set copySheet = Worksheets("Sheet2")
Set pasteSheet = Worksheets("Sheet1")
copySheet.Range("A1").CurrentRegion.Offset(1, 0).Copy pasteSheet.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
Application.CutCopyMode = False

'Put todays date in column A
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
With Range("A2:A" & LastRow)
.Value = Date
.NumberFormat = "dd/mm/yy"
End With


Application.ScreenUpdating = True
End Sub
[/CODE]

The problem is that the code replaces yesterday's date with today. It only puts in todays date in column A and does not keep any previous dates.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
try this:

Code:
Sub VbaGreenHorn1()
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With Range("A2:A" & LastRow).SpecialCells(4)
    .Value = Date
    .NumberFormat = "dd/mm/yy"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

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