Solved

copy data validation using VBA

Posted on 2013-06-14
6
597 Views
Last Modified: 2013-06-14
I have a macro which creates a Data Validation in cell R11.

I need to copy this down in every cell where the row is not blank. The number of rows changes every day.

can someone provide VBA code that will copy this down

thanks
0
Comment
Question by:Jagwarman
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:Michael
ID: 39246972
Hi Jagwarman,

can you post the code of this macro you're referring to?
And which column can be used as a reference for checking what the last row is (which column always has a value in the last row)?

Thanks
Joop
0
 

Author Comment

by:Jagwarman
ID: 39247100
I have created a 'category' which is on Sheet3 which is then hidden.

Sub Category()
'
' Category Macro
'

'
   
    Sheets("Today").Select
    Range("R11").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Category"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
   
         
End Sub
0
 
LVL 6

Expert Comment

by:Michael
ID: 39247119
Ok, and how about:

which column can be used as a reference for checking what the last row is (which column always has a value in the last row)?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Jagwarman
ID: 39247139
sorry missed that question.

Column 'A'
0
 
LVL 6

Accepted Solution

by:
Michael earned 500 total points
ID: 39247151
No problem, happens to the best ;)

Try the following code.
It sets a range in column R from row 11 to the last. Then it applies your validation to every cell in that range that is not empty.
Remember to try it on a copy of your original workbook.
Sub categoryRange()
    
Application.ScreenUpdating = False

Dim rngCategory As Range
    Dim cell As Range
    
    With Sheets("Today")
        Set rngCategory = .Range("R11:R" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        For Each cell In rngCategory
            If cell.Value <> "" Then
                With cell.Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=Category"
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            End If
        Next cell
    End With

Application.ScreenUpdating = True
    
End Sub

Open in new window

0
 

Author Closing Comment

by:Jagwarman
ID: 39247313
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now