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

Jay3

Board Regular
Joined
Jul 3, 2009
Messages
237
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
 
Upvote 0
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
 
Upvote 0
That is looking at col F, but you said it's in col H
 
Upvote 0
Yeah it's now f. So that bit of the code works. Just need to figure out the rest of it. Any ideas?
 
Upvote 0
So is that something the "Create_Project_Board" procedure should be doing, or do you need to do that before calling the other procedure?
 
Upvote 0
So the code needs to run as part of the create project board procedure. That's what I need to write.
 
Upvote 0
What code have you already got?
 
Upvote 0
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.
 
Upvote 0
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

  • Capture.PNG
    Capture.PNG
    31.4 KB · Views: 2
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,695
Members
448,293
Latest member
jin kazuya

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