Solved

copy data validation using VBA

Posted on 2013-06-14
6
679 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

738 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