Solved

VBA Code to avoid hard coded selection

Posted on 2012-04-05
3
323 Views
Last Modified: 2012-04-05
Dear experts:

below code inserts data validation into cells E3:E1450 of the active worksheet.

I do not want to hardcode the selection but check by means of VBA Code the number of Rows in COLUMN B first and insert that number into the second part of the Range ("E3:E1450").

Example: The number of columns / filled cells of column B is 1872. This number is to be transferred to the line of code where the Range (second part of the seclection) is selected, i.e.

Range("E3:E1872").Select.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub MacroDataValidation()

    Range("E3:E1450").Select
    With Selection.Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=DD_Range"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub
0
Comment
Question by:AndreasHermle
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
kgerb earned 500 total points
ID: 37811723
Hello Andreas,
Try this.

Kyle
Sub MacroDataValidation()
    With Range("E3:E" & Cells(Rows.Count, "B").End(xlUp).Row).Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=DD_Range"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 37814506
Hi Kyle,

this did the trick! Thank you very much for your professional and swift support.  I really appreciate it.

Regards, Andreas
0
 
LVL 12

Expert Comment

by:kgerb
ID: 37814851
You're welcome.  Glad to help.

Kyle
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
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 use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

770 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