Macro for Data Validation of Work Sheets

jareddmccullough

New Member
Joined
Feb 9, 2012
Messages
4
I have a data validation say in sheet "A" it currently operates of a set validation which references other sheet
names by me manually inputing references in a list say cell M:M of worksheet "A". This is creating some

difficulty because my list of worksheets keeps growing. My plan is to create a macro to operate this validation
within module (Worksheet) code. What I want it to do is collect all other titles except worksheet "A" into a

data validation. I feel this is a more simple task than what I am making it but seem to have a brain block at

the moment and need it pretty asap. So far I have come up with this. PLEASE HELP and thank you.

Private Sub Worksheet_Activate()
Dim ws As Worksheet, RNG As Range, r As Range, rCHCK As Range, buf As String
On Error Resume Next
For Each ws In Worksheets
If (ws.Name) Then
Next ws

Range("Z2").CurrentRegion.Sort Range("Z2"), xlAscending, Header:=xlNo
buf = Join(WorksheetFunction.Transpose(Range("Z:Z").SpecialCells(xlConstants)), ",")
With Range("E2").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=buf
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Range("Z:Z").ClearContents
End Sub

I have used this code in other context but cant seem to figure out how to apply it.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,203,686
Messages
6,056,736
Members
444,887
Latest member
cvcc_wt

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