Hi Guys
I am trying to do couple of things.
I want to compare the Department name in Sheet “Total employee” range A2:G2, with the other sheet names in the workbook. If the column value that is A2:G2 in Total employee (Department Name) not found in worksheet sheet names then, I want a message box “Sheet (name) not found, would you like to create one” and if user select Yes, then then the new sheet has to be created.
The new sheet has to be created with the similar format like Policy, Marketing, finance with the relevant data from Total employee sheet.
For example, there is no sheet name called HR in workbook.
But in Sheet “Total employee” Department Name HR is present
I want to create, a sheet name called HR and in that worksheet, I want to insert data based on sheet name
HR
LocationName Total employees Annual Salary Date of Join
Location1 2
Location3 7
Location6 3
I am started on it, but i am struck in the beginning state itself.
Anyone help is much appreciated.
Sub worksheetcheck()
Dim wb As Workbook
Dim sitename As String
Dim rng As Range
Dim i As Integer
i = Application.Sheets.Count
worksheetexist = False
Set rng = ThisWorkbook.Sheets("Total employees").Range("b2:G2")
For Each cell In rng
For x = 1 To i
'
If cell.Value <> Worksheets(x).Name Then
MsgBox cell.Value
Exit For
End If
Next x
Next cell
End Sub
Bookmarks