Solved

copy data validation using VBA

Posted on 2013-06-14
6
575 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

759 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

19 Experts available now in Live!

Get 1:1 Help Now