Insert a new row based on a specific column value

kris_excel

New member
Joined
May 14, 2015
Messages
8
Reaction score
0
Points
0
Hi Gurus,

I need some help on the below situation. I have columns from A to L with headers starting from Sl. No, Goal Name, Activity Name... etc.,
Under 'Goal Name' header, I have Goal 1, Goal 2, etc., For each Goal, I have multiple activities.
For ex: For Goal 1, I have 3 activities below. Likewise, for Goal 2, I have 2 activities and so on.

Now I want to use macros, let's assume, I place a command button on this page and click on it, would ask me which 'Goal' I need to add a blank row at the end of the that particular Goal populated row.

For ex: If I click on command button, it will ask the 'Goal Name'. I enter 'Goal 1' and then immediately, it should add a blank row below the row of 'Activity 1.2'. Likewise, If I enter 'Goal 2', a blank row should be added below 'Activity 2.1'.

Kudos in advance for your help.


Sl. NoGoal NameActivity NameActivity WBSTeamPriorityPlan Start DateActual Start DatePlan End DateActual End DateStatus% Complete
clip_image002.png
1Goal 1Activity 1WBS 1Team 1
Activity 1.1WBS 1.1Team 1.1
Activity 1.2WBS 1.2Team 1.2
2Goal 2Activity 2WBS 2Team 2
Activity 2.1WBS 2.1Team 2.1
3Goal 3Acitivity 3WBS 3Team 3
4Goal 4Activity 4WBS 4Team 4
 
Good Morning All.. Appreciate if anyone provides a solution on this... Thanks in advance...
 
I could able to initiate design and added some code. I inserted a command button on the sheet and clicking on it, invoked a user form:

Private Sub cmdOpenForm_Click()

frmData.Show

End Sub


In the user form, added Goal Name list box with values in it, added another command button. Clicking on the command button in the user form adding a blank row in the sheet. Code below:

Private Sub frmAddRow_Click()

If lstGoalName.Value = "Goal 1" Then

Sheets("Sheet2").Range("A8").Select
ActiveCell.EntireRow.Insert Shift:=xlDown


Sheets("Sheet2").Range("A8:L8").Select
Selection.Borders.Weight = xlThin


ElseIf lstGoalName.Value = "Goal 2" Then


Sheets("Sheet2").Range("A11").Select
ActiveCell.EntireRow.Insert Shift:=xlDown


Sheets("Sheet2").Range("A11:L11").Select
Selection.Borders.Weight = xlThin

End If

End Sub


Private Sub UserForm_Initialize()

lstGoalName.RowSource = "Sheet2!AM1:AM4"

End Sub


However, in the code above, rows are fixed with A8 and A11 etc., for each goal 1, goal 2, etc., But adding few blank rows, it's jumbling up. So can you help me to enhance this code so that when I try to add a blank row it should check what is the last populated row for this particular goal and add a blank row underneath. For ex: If I select 'Goal 1' in the list box of user form and click on the add row button, it should check what is the last activity in the 'Activity Name' column for that particular Goal 1. It should find the last populated activity and then add a blank under it.

Please help.
 
Back
Top