Solved

copy data validation using VBA

Posted on 2013-06-14
6
623 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
locking multiple column ranges 10 25
Excel Formula 16 46
Clear Filter 8 40
Copying from excel I am getting extra text 11 44
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

803 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