Fill in a column if other columns in the row are not empty

Using

  • 2007 Microsoft Office Excel Macro Worksheet
  • Microsoft Visual Basic

I was looking for ways to solve my problem and could not find a key to solve this problem.

Case

In the sheet, I need to automatically insert the value (static timestamp) into the column immediately after the specified range of columns based on the condition that they are not all zero (filled).

Goal Example

Given the order in which the values ​​are inserted into the rows one after the other, when the values ​​in the column range A:Care filled, I would like the column to be updated D(the next after the specified range).

ColumnA ColumnB ColumnC AutoInsert
filled  filled  filled  2016-01-11 20:57
filled  filled      
filled          
filled  filled  filled  2016-01-11 20:58

What I have?

, A B.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("A:A")) Is Nothing Then
            With Target(1, 2)
                .Value = Now
            End With
        End If
End Sub

:

ColumnA AutoInsert
value   2016-01-11 21:06
value   2016-01-11 21:06
value   2016-01-11 21:07

?

- , , ( , ?).

, - , Intersect, - . Target(x, y) Range("A:C"), , , .

+4
1

:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
            If Not Intersect(Target, Range("A:C")) Is Nothing And WorksheetFunction.CountBlank(Range("A" & Target.Row & ":C" & Target.Row)) = 0 Then
                With Me.Cells(Target.Row, 4)
                    Application.EnableEvents = False
                    .value = Now
                End With
            End If
    Application.EnableEvents = True
End Sub

Me . , . , ActiveSheet. .Cells - . Cells(Row,Column). Me.Range("D" & Target.row).

- , Target(row,column) - Target.Cells(row,column). Target(1,4). Target(1,1) . , .

+4

Source: https://habr.com/ru/post/1623823/


All Articles