VB Script (Excel) help.

mwvirk

Active Member
Joined
Mar 2, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
following script will check cell ‘I’ and if there is something then it will fill date in ‘L’ and time in ‘M’
Then going down in this script; if you enter data in cell ‘T’ then it will insert current date in cell ‘U’
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Problem is that my data is only up-to row 210 (minimum) or 350 (maximum) but if I enter something anywhere in the sheet in cell ‘I’ or ‘T’ it will still fill cell ‘L’ – ‘M’ (if data is entered in cell ‘I’) and fill current date in cell ‘U’ (if something is entered in cell ‘T’)
<o:p> </o:p>
Only possibility to stop it is to keep checking cell ‘A’ – if there is something in cell a then cell ‘I’ or/and cell ‘T’ should accept enter otherwise leave the sheet as it is.
<o:p> </o:p>
Please help – thanks.
---------------------------------
<o:p> </o:p>
Option Explicit
<o:p> </o:p>
Private Sub Worksheet_Change(ByVal Target As Range)
Dim irow As Long
If Not Intersect(Target, Range("I:I")) Is Nothing Then
On Error Resume Next
Application.EnableEvents = False
irow = Target.Row
'if there is a date in column L end the macro
<o:p> </o:p>
If IsEmpty(Target) Then
Target.Offset(0, 3).ClearContents
Target.Offset(0, 5).ClearContents
GoTo EndProc
End If
If IsDate(Target.Offset(0, 3)) Then GoTo EndProc
Target.Offset(0, 3) = Date
Target.Offset(0, 5) = Time
End If
'---------------------------------
If Not Intersect(Target, Range("T:T")) Is Nothing Then
On Error Resume Next
Application.EnableEvents = False
irow = Target.Row
'if there is a date in column L end the macro
<o:p> </o:p>
If IsEmpty(Target) Then
Target.Offset(0, 1).ClearContents
GoTo EndProc
End If
If IsDate(Target.Offset(0, 3)) Then GoTo EndProc
Target.Offset(0, 1) = Date
End If
EndProc:
Application.EnableEvents = True
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try putting this at the begiining of your procedure:

Code:
If Len(Range("A" & Target.Row).Value) = 0 Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,254
Members
452,900
Latest member
LisaGo

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