Small data set...no need for arrays...Here is a easy enough loop to understand...
However, something tells me that there is more to this than meets the eye so to say...
i.e. look at data5 in attached file...I added this after the first run of the macro...If Label6 does not yet exist the data will be entered into a new column and values entered just below...Does this not have to be entered into first new row based on column A?
Anyway have a look and explain requirement in more detail...
Private Sub CommandButton1_Click()
Dim Fnd As Range, cell As Range, lc As Long, lr As Long, nr As Long
With Sheets("Change_Log")
For Each cell In Sheets("Data").UsedRange.SpecialCells(xlCellTypeConstants)
If IsNumeric(cell) Then
lc = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
If lc = 2 Then
lc = 5
Else
Set Fnd = .Rows(1).Find(cell.Offset(, -1).Value, , xlValues, xlWhole)
If Not Fnd Is Nothing Then lc = Fnd.Column
End If
.Cells(1, lc) = cell.Offset(, -1)
nr = .Cells(.Rows.Count, lc).End(xlUp).Row + 1
.Cells(nr, lc) = cell: If .Cells(nr, 1) = "" Then .Cells(nr, 1).Resize(, 3) = Array("Time Stamp", Date, Format(Now(), "HH:MM:SS"))
End If
Next cell
.Activate
End With
End Sub
Bookmarks