PDA

View Full Version : exclude some worksheets according to a list of the name of worksheet



clarksonneo
06-14-2011, 09:44 AM
Hi,

In my workbook, there are 10 worksheets.

The name of a worksheet is Master.
The names of the rest of the worksheets are sheet 1, sheet 2, sheet 3, .... , sheet 9.

I want a macro that will type "a" in cell A1 on worksheet sheet 1 to sheet 9.
I understand the macro.

The difficult thing is here.
On the master worksheet, on column a, I will type the name of the worksheet which I want to exclude them from typing "a" in cell A1 as mentioned above.

For example, if I type sheet 1, sheet 2 ... sheet 5 in column a on the master sheet(1 cell per name), then "a" will only typed in cell A1 on sheet 6 to sheet 9.


could you please write me the macro?

thanks

Kenneth Hobs
06-14-2011, 11:35 AM
Sub CopyA()
Dim c As Range, ws As Worksheet
For Each c In Worksheets("Master").Range("A1", Worksheets("Master").Range("A" & Rows.Count).End(xlUp))
On Error Resume Next
Set ws = Worksheets(c.Value2)
If Not ws Is Nothing Then ws.Range("A1").Value2 = "a"
Next c
End Sub

clarksonneo
06-15-2011, 01:49 AM
Sub CopyA()
Dim c As Range, ws As Worksheet
For Each c In Worksheets("Master").Range("A1", Worksheets("Master").Range("A" & Rows.Count).End(xlUp))
On Error Resume Next
Set ws = Worksheets(c.Value2)
If Not ws Is Nothing Then ws.Range("A1").Value2 = "a"
Next c
End Sub

hi,

thank you for your code
I have tried


this is converse to what i need

however,
when I write sheet 1 - sheet 5 on the master worksheet colmun A, then "a" will be typed on sheet 1 - sheet 5.
Sheet 6 -sheet 9 have nothing.


i hope that
when I write sheet 1 - sheet 5 on the master worksheet colmun A, then "a" will be typed on sheet 6 - sheet 9.
Sheet1 -sheet 5 have nothing.



thanks

Kenneth Hobs
06-15-2011, 06:02 AM
Sub CopyA()
Dim ws As Worksheet, fRange As Range, f As Range
Set fRange = Worksheets("Master").Range("A1", Worksheets("Master").Range("A" & Rows.Count).End(xlUp))
For Each ws In Worksheets
Set f = fRange.Find(ws.Name)
If Not f Is Nothing And ws.Name <> "Master" Then ws.Range("A1").Value2 = "a"
Next ws
End Sub