Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

copy data validation using VBA

Posted on 2013-06-14
6
Medium Priority
?
761 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
Independent Software Vendors: 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!

 

Author Comment

by:Jagwarman
ID: 39247139
sorry missed that question.

Column 'A'
0
 
LVL 6

Accepted Solution

by:
Michael earned 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

704 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