vivekvasan
New Member
- Joined
- Feb 16, 2017
- Messages
- 12
Hello Experts,
I'm relatively new to vba coding and have been trying to wrap my head around to get this resolved. I have a requirement to generate serial# based on the present date (in a particular format) thru a command button. The generated serial number should be registered in a particular column. I keyed in the following code and it seems to work except for 2 issues.
The issues are:
1) When the command button is hit, the serial number generated based on earlier date gets over-rided by today's date (which is not supposed to happen as this is a running log with previous information required as-is).
2) I require this format to be generated from 5th row of a particular column (since there are other contents in the first 4 rows), however, this code over-rides existing contect and starts appearing from the first row on.
Please share your inputs. Thanks.
Code written so far that has existing 2 issues mentioned above:
Sub GENERATE_LOG()
Dim d As String
Dim n As Long, i As Long,
Dim ws As Worksheet
Set ws = Worksheets("LOGFILE")
d = VBA.Format(Date, "YYYY-MMDD")
With ws
n = .Cells(.Rows.Count, "AE").End(xlUp).Row
For i = 1 To n
.Cells(i + 1, 31).Value = d & "-" & i
Next i
End With
End Sub
I'm relatively new to vba coding and have been trying to wrap my head around to get this resolved. I have a requirement to generate serial# based on the present date (in a particular format) thru a command button. The generated serial number should be registered in a particular column. I keyed in the following code and it seems to work except for 2 issues.
The issues are:
1) When the command button is hit, the serial number generated based on earlier date gets over-rided by today's date (which is not supposed to happen as this is a running log with previous information required as-is).
2) I require this format to be generated from 5th row of a particular column (since there are other contents in the first 4 rows), however, this code over-rides existing contect and starts appearing from the first row on.
Please share your inputs. Thanks.
Code written so far that has existing 2 issues mentioned above:
Sub GENERATE_LOG()
Dim d As String
Dim n As Long, i As Long,
Dim ws As Worksheet
Set ws = Worksheets("LOGFILE")
d = VBA.Format(Date, "YYYY-MMDD")
With ws
n = .Cells(.Rows.Count, "AE").End(xlUp).Row
For i = 1 To n
.Cells(i + 1, 31).Value = d & "-" & i
Next i
End With
End Sub