Need A macro to inseet new sheets with given names

Dilusha

Board Regular
Joined
May 5, 2012
Messages
58
I have following data in sheet1(Column A)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]SSS
[/TD]
[/TR]
[TR]
[TD]SSS
[/TD]
[/TR]
[TR]
[TD]EXP
[/TD]
[/TR]
[TR]
[TD]KIK
[/TD]
[/TR]
[TR]
[TD]KIK
[/TD]
[/TR]
[TR]
[TD]KIK
[/TD]
[/TR]
[TR]
[TD]MIC
[/TD]
[/TR]
[TR]
[TD]SNS
[/TD]
[/TR]
[TR]
[TD]SNS
[/TD]
[/TR]
[TR]
[TD]TRF

[/TD]
[/TR]
</tbody>[/TABLE]

I want to insert new sheets by giving above names to same work book(only one sheet for one name. here 6 sheets ) . column A is sorted .
I use excel 2007 -in my lap top .
please help me .
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
See if this does what you want.
Code:
Sub Add_Sheets()
  Dim c As Range
  Dim ws As Worksheet
  
  With Sheets("Sheet1")
    For Each c In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
      On Error Resume Next
      Set ws = Sheets(c.Value)
      On Error GoTo 0
      If ws Is Nothing Then Sheets.Add.Name = c.Value
      Set ws = Nothing
    Next c
  End With
End Sub

Or you might want this for the line that adds the sheets
Code:
If ws Is Nothing Then Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
 
Last edited:
Upvote 0
See if this does what you want.
Code:
Sub Add_Sheets()
  Dim c As Range
  Dim ws As Worksheet
  
  With Sheets("Sheet1")
    For Each c In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
      On Error Resume Next
      Set ws = Sheets(c.Value)
      On Error GoTo 0
      If ws Is Nothing Then Sheets.Add.Name = c.Value
      Set ws = Nothing
    Next c
  End With
End Sub

Or you might want this for the line that adds the sheets
Code:
If ws Is Nothing Then Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value




it workes
thanks a lot
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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