Copy a worksheet and rename it to the project name in a given cell.

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
Hi All,

I have a sheet called "new project requiring board". in column H I have a Yes/No drop down validation list.

If the user selects yes I would like a template / worksheet tab called 'Project Board Template' to be duplicated and renamed to the project name in the corresponding row in col A of "new project requiring board"

My code to trigger this event is on lines 11 -16 of the following script, it would be great if someone could help with this.

Many thanks =D

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldValue As String
  Dim NewValue As String

  ' don't trigger any events if user is making some sort of change to multiple
  ' rows or columns simultaneously
  If Target.Cells.Count > 1 Then Exit Sub
 
  If Target.Column = 1 Then ThisWorkbook.Save
 
  If Not Intersect(Target, Columns("F")) Is Nothing Then
    If Target.Value = "YES" Then
      Call Create_Project_Board(Target.Row)
      ThisWorkbook.Save
    End If
  End If
 
    
 If Not Intersect(Target, Columns("F")) Is Nothing Then
    Select Case Target.Value
      Case "YES"
        NewValue = Target.Value
        Application.EnableEvents = False
        Application.Undo
        OldValue = Target.Value
        Target.Value = NewValue
        Application.EnableEvents = True
        If OldValue = "NO" Then
          ThisWorkbook.Save
            If Target.Value = "YES" Then
              MsgBox "Project Board Already Created"
            End If
        End If
      Case "NO"
        NewValue = Target.Value
        Application.EnableEvents = False
        Application.Undo
        OldValue = Target.Value
        Target.Value = NewValue
        Application.EnableEvents = True
        If OldValue = "YES" Then
          ThisWorkbook.Save
             If Target.Value = "NO" Then
              MsgBox "Should we offer to delete the board here?"
            End If
        End If
    End Select
  End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

  If Not Intersect(Target, Columns("B")) Is Nothing Then
    If IsEmpty(Target) Then
      ThisWorkbook.Save
    End If
  End If

End Sub
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,637
Office Version
365
Platform
Windows
I've no idea which line you are referring to by lines 11-16, but the obvious point is that none of that code is looking at col H
 

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
This code triggers the event

VBA Code:
If Not Intersect(Target, Columns("F")) Is Nothing Then
    If Target.Value = "YES" Then
      Call Create_Project_Board(Target.Row)
      ThisWorkbook.Save
    End If
  End If
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,637
Office Version
365
Platform
Windows
That is looking at col F, but you said it's in col H
 

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
Yeah it's now f. So that bit of the code works. Just need to figure out the rest of it. Any ideas?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,637
Office Version
365
Platform
Windows
So is that something the "Create_Project_Board" procedure should be doing, or do you need to do that before calling the other procedure?
 

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
So the code needs to run as part of the create project board procedure. That's what I need to write.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,637
Office Version
365
Platform
Windows
What code have you already got?
 

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
This is one I'm starting from scratch. I'm going to have a look again today. I guess the starting point is to use the recorder.
 

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
232
Ok a little further with this. My code so far:

VBA Code:
Option Explicit
 
Sub Create_Project_Board(ByVal aRow As Long)
'if Yes is selected in column F check if a board has already been created with the corresponding project name. If yes then do nothing if not then create
'To create the board copy the tab called Project Template Board and rename the tab to the corresponding project name in cell A.
'Once done update project title and assigned to fields in c2 and c3 and also the project description in F by copying this information from the New Project
'Requiring Board tab

 
Dim wsName As String
Dim wsData As Worksheet
 
wsName = wsData.Range("A" & aRow).Value
Sheets("Project Board Template").Select
Sheets("Project Board Template").Copy Before:=Sheets(5)
Range("B2").Select
ActiveCell.FormulaR1C1 = wsName
Sheets("Project Board Template (2)").Select
Sheets("Project Board Template (2)").Name = wsName
Sheets("New Project Requiring Board").Select

End Sub
I'm getting an error on this line:

Code:
wsName = wsData.Range("A" & aRow).Value
Screen shot attached.
 

Attachments

Forum statistics

Threads
1,089,518
Messages
5,408,757
Members
403,224
Latest member
rholmesa

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top