D
daniel chen
From any empty cell, I enter the company name,.
The following macro will validate the name with the index in column A of
worksheet named "Jounal"
This index lists all the worksheets bearing their names.
If valid, it will direct to that worksheet.
If it is not valid, I want to create one automatically bearing the name.
For example, if I enter Acer in any empty cell, run the macro and enter "y"
at prompt,
it will create Worksheet("Acer") and be selected.
Will someone help me to do that? Please.
Sub Macro1()
Dim reg As String
Dim regSht As String
Dim Ans As String
Dim NextRow As Integer
reg = ActiveCell.Value
If reg = "" Then Exit Sub
' I had manually created Worksheet("Jounal"),
'Worksheet("Apple"), Worksheet("Dell") and Worksheet("HP").
regSht = "Jounal"
Sheets(regSht).Select
Range("A1") = "Index:" ' as given
Range("A2") = "Jounal" ' as given
Range("A3") = "Apple" ' as given
Range("A4") = "Dell" ' as given
Range("A5") = "HP" ' as given
regSht = ""
If Not IsError(Application.Match(reg, Range("A2:A10"), 0)) Then
Sheets(reg).Select
GoTo proceeding1
Else
Ans = InputBox(prompt:="No such so" & vbLf & _
"Enter 'y' to create a new worksheet" & vbLf &
"Enter 'n' to abort")
If Ans = "y" Then GoTo Create_worksheet
If Ans = "n" Then Exit Sub
End If
Create_worksheet:
With Worksheets("Jounal")
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Cells(NextRow, 1) = reg
' I need help here to create a new worksheet. ?!?!?!?!?!?!?!
proceeding1:
End Sub
The following macro will validate the name with the index in column A of
worksheet named "Jounal"
This index lists all the worksheets bearing their names.
If valid, it will direct to that worksheet.
If it is not valid, I want to create one automatically bearing the name.
For example, if I enter Acer in any empty cell, run the macro and enter "y"
at prompt,
it will create Worksheet("Acer") and be selected.
Will someone help me to do that? Please.
Sub Macro1()
Dim reg As String
Dim regSht As String
Dim Ans As String
Dim NextRow As Integer
reg = ActiveCell.Value
If reg = "" Then Exit Sub
' I had manually created Worksheet("Jounal"),
'Worksheet("Apple"), Worksheet("Dell") and Worksheet("HP").
regSht = "Jounal"
Sheets(regSht).Select
Range("A1") = "Index:" ' as given
Range("A2") = "Jounal" ' as given
Range("A3") = "Apple" ' as given
Range("A4") = "Dell" ' as given
Range("A5") = "HP" ' as given
regSht = ""
If Not IsError(Application.Match(reg, Range("A2:A10"), 0)) Then
Sheets(reg).Select
GoTo proceeding1
Else
Ans = InputBox(prompt:="No such so" & vbLf & _
"Enter 'y' to create a new worksheet" & vbLf &
"Enter 'n' to abort")
If Ans = "y" Then GoTo Create_worksheet
If Ans = "n" Then Exit Sub
End If
Create_worksheet:
With Worksheets("Jounal")
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Cells(NextRow, 1) = reg
' I need help here to create a new worksheet. ?!?!?!?!?!?!?!
proceeding1:
End Sub