VBA code to add row and Task ID

flea80

New Member
Joined
Feb 15, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have created a to-do list and want a button to add a new row which has a task ID in the first column.

taskid.png

For now I have the following code for a new row:
VBA Code:
Sub Add_Row()

Dim Test As Worksheet
Set Test = ThisWorkbook.Sheets("TEST")
Test.Range("A11").End(xlDown).Select
ActiveCell.Offset(1, 0).EntireRow.Insert
ActiveCell.Offset(1, 0).Select

End Sub

What code do I have to add to create a new row that starts with (in this case) T0007?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi flea80,

You might consider something like this. I tested it, and it works. Good luck, and let me know how you make out.

VBA Code:
Sub AddRow()

Dim TaskID As String
Dim Row As Long

TaskID = "T" & Format(Range("A" & Rows.Count).End(xlUp).Row + 1, "0000")

Row = Range("A" & Rows.Count).End(xlUp).Row + 1

Range("A" & Row).Value = TaskID

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,239
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top