Thread: VBA Query
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default VBA Query

Hi Missk,

Replace Sub Tester01 wth the following more robust version:

'=============
Public Sub Tester01A()
Dim rng As Range
Dim LRow As Long

LRow = Cells(Rows.Count, "B").End(xlUp).Row

On Error Resume Next
Set rng = Range("A2:A" & LRow).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If Not rng Is Nothing Then rng.Value = Date

End Sub
'<<=============


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Missk,

Try assigning the following macro to a button:

'=============
Public Sub Tester01()
Dim rng As Range
Dim LRow As Long

LRow = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("A2:A" & LRow).SpecialCells(xlCellTypeBlanks)

rng.Value = Date

End Sub
'<<=============


Alternatively, If you wish column A to be populated dynamically, in
response to entries in column B, try:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim rCell As Range

Set rng = Intersect(Columns(2), Target)

If Not rng Is Nothing Then
For Each rCell In rng.Cells
With rCell.Offset(0, -1)
If IsEmpty(.Value) Then
If Not IsEmpty(rCell.Value) Then
.Value = Date
End If
End If
End With
Next rCell
End If
End Sub
'<<=============

The latter sub represents worksheet event code and should be pasted into
the worksheets's code module (not a standard module and not the workbook's
ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman