Solved

VBA Code to avoid hard coded selection

Posted on 2012-04-05
3
321 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

895 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

16 Experts available now in Live!

Get 1:1 Help Now