THX1138
New Member
- Joined
- Feb 2, 2003
- Messages
- 46
after searching the forum for a solution I have managed to get close to what I need. What I am trying to create is a master sheet that has some vlaues in it. This is then used to generate other sheets with further details for each row item.
Below is the code, what I need is for this code to allow there to be text, numerical data, etc. in the cells to the left (referred in the code as b1,b2, and so on).
Right now the code will not exicute unless the cells are blank.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
If Target.Column = 2 And Target.Row > 1 And Target.Offset(0, 1) = vbNullString _
And Target <> vbNullString Then
Dim ws As Worksheet
Set ws = Me.Parent.Sheets.Add(After:=Me.Parent.Sheets(Me.Parent.Sheets.Count))
With ws
On Error Resume Next
.Name = Target.Offset(0, -1)
If Err.Number <> 0 Then
MsgBox "Unable to create new worksheet.", vbOKOnly + vbCritical, "Error"
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
Set ws = Nothing
Exit Sub
End If
On Error GoTo 0
.Range("A1:A6") = Application.Transpose(Array("PRIORITY", "PART NUMBER", "DESCRIPTION", "TYPE", "REQUESTED BY", "COMMENTS"))
.Range("B1") = Target.Value
.Range("B2") = Target.Offset(0, 1)
.Range("B3") = Target.Offset(0, 2)
.Range("B4") = Target.Offset(0, 3)
.Range("B5") = Target.Offset(0, 4)
.Range("B6") = Target.Offset(0, 5)
End With
Application.EnableEvents = False
Me.Hyperlinks.Add Target.Offset(0, 6), Address:=vbNullString, SubAddress:="'" & ws.Name & "'!A1", _
TextToDisplay:="PART MASTER SHEET"
Application.EnableEvents = True
Set ws = Nothing
Me.Activate
End If
End If
End Sub
Any and all help will be greatly appreciated.
Below is the code, what I need is for this code to allow there to be text, numerical data, etc. in the cells to the left (referred in the code as b1,b2, and so on).
Right now the code will not exicute unless the cells are blank.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
If Target.Column = 2 And Target.Row > 1 And Target.Offset(0, 1) = vbNullString _
And Target <> vbNullString Then
Dim ws As Worksheet
Set ws = Me.Parent.Sheets.Add(After:=Me.Parent.Sheets(Me.Parent.Sheets.Count))
With ws
On Error Resume Next
.Name = Target.Offset(0, -1)
If Err.Number <> 0 Then
MsgBox "Unable to create new worksheet.", vbOKOnly + vbCritical, "Error"
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
Set ws = Nothing
Exit Sub
End If
On Error GoTo 0
.Range("A1:A6") = Application.Transpose(Array("PRIORITY", "PART NUMBER", "DESCRIPTION", "TYPE", "REQUESTED BY", "COMMENTS"))
.Range("B1") = Target.Value
.Range("B2") = Target.Offset(0, 1)
.Range("B3") = Target.Offset(0, 2)
.Range("B4") = Target.Offset(0, 3)
.Range("B5") = Target.Offset(0, 4)
.Range("B6") = Target.Offset(0, 5)
End With
Application.EnableEvents = False
Me.Hyperlinks.Add Target.Offset(0, 6), Address:=vbNullString, SubAddress:="'" & ws.Name & "'!A1", _
TextToDisplay:="PART MASTER SHEET"
Application.EnableEvents = True
Set ws = Nothing
Me.Activate
End If
End If
End Sub
Any and all help will be greatly appreciated.