Solved

VBA Code to avoid hard coded selection

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA modules import 4 57
VBA or Script to identify files which are duplicate in a folder 6 34
Excel Macro 9 22
VBA working with shapes 6 11
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

830 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