enter value line by line

  • Thread starter Thread starter ave_ave
  • Start date Start date
A

ave_ave

Hi,

I’m just to new to this excel programming, can you teach me how t
write this program?

My program is like this,

I have one command button, every time when I press the button, it wil
store current date time to first row first column (A1), after that, i
I press again, it will store another current date time to the followin
row (A2). For this first part, I already figure out( finally ^_^’), bu
come to second part, I have some problem… I don know how to move th
data to second column. So, can you teach me how to write this part?

Thx you

Ave_av
 
At what point will it move to the second column?

Private Sub Command_button1_click()
Dim rng as Range, rng1 as Range
set rng1 = Range("A1")
if isempty(rng1) then
set rng = rng1
elseif isempty(rng1(2)) then
set rng = rng1(2)
else
set rng = rng1.End(xldown)(2)
end if
rng.Value = now
rng.format = "mm/dd/yyyy hh:mm:ss")
rng.EntireColumn.Autofit
End Sub
 
How do you know when to start on the second column?

Maybe if you've already entered values in the first 10 rows?

This may be a little overkill, since it checks a few things that may not need to
be checked.

Option Explicit
Sub testme()

Dim myCell As Range
Dim iCol As Long

Set myCell = Nothing
With ActiveSheet
For iCol = 1 To .Columns.Count '256
Set myCell = .Cells(.Rows.Count, iCol).End(xlUp)
If IsEmpty(myCell) Then
'do nothing
Else
Set myCell = myCell.Offset(1, 0)
End If
If myCell.Row < 11 Then
Exit For
Else
'keep going
End If
Next iCol
End With

If myCell Is Nothing Then
MsgBox "ran out of columns!!!"
Else
With myCell
.Value = Date
.NumberFormat = "mm/dd/yyyy"
End With
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top