M
mwam423
greetings, i pulled the following code from ms. dalgleish's data validation
file and would like the macro to stop once it reaches at certain row, if the
last number is continually overwritten that's fine.
i've tried if statements based on "target.row + 1" being less than a
numerical value, say 10, but that doesn't seem to work (if someone could clue
me into why that'd be great. any help appreciated, and props to ms.
dalgleish and her fab, i.e. incredibly useful, website =D
http://www.contextures.com/index.html
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo exitHandler
Dim rngDV As Range
Dim lRow As Long
Dim lCol As Long
lCol = Target.Column 'column with data validation cell
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Select Case Target.Column
Case 2, 3, 4, 5, 6
If Target.Offset(1, 0).Value = "" Then
lRow = Target.Row + 1
Else
lRow = Cells(Rows.Count, lCol).End(xlUp).Row + 1
End If
Cells(lRow, lCol).Value = Target.Value
End Select
End If
exitHandler:
Application.EnableEvents = True
End Sub
file and would like the macro to stop once it reaches at certain row, if the
last number is continually overwritten that's fine.
i've tried if statements based on "target.row + 1" being less than a
numerical value, say 10, but that doesn't seem to work (if someone could clue
me into why that'd be great. any help appreciated, and props to ms.
dalgleish and her fab, i.e. incredibly useful, website =D
http://www.contextures.com/index.html
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo exitHandler
Dim rngDV As Range
Dim lRow As Long
Dim lCol As Long
lCol = Target.Column 'column with data validation cell
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Select Case Target.Column
Case 2, 3, 4, 5, 6
If Target.Offset(1, 0).Value = "" Then
lRow = Target.Row + 1
Else
lRow = Cells(Rows.Count, lCol).End(xlUp).Row + 1
End If
Cells(lRow, lCol).Value = Target.Value
End Select
End If
exitHandler:
Application.EnableEvents = True
End Sub