+ Reply to Thread
Results 1 to 4 of 4

Creating a macro to generate a list for hundreds of rows

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2015
    Location
    United States
    MS-Off Ver
    2013
    Posts
    67

    Creating a macro to generate a list for hundreds of rows

    Hi -

    I'm trying to create a macro that will create a list for hundreds of rows. I created the first portion of the macro, however needing help on how to apply from rows 6-462. Please note each row has specific selection options.
     Range("D5").Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=$AU$5:$AX$5"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    End Sub

    As you can see cell D5, needs to have the list options of AU5:AX5. Looking on how to carry this down to D462 with the list option of AU462:AX462. Any help is greatly appreciated.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Creating a macro to generate a list for hundreds of rows

    You may try something like this.....

    Sub InsertDataValidation()
    Dim i As Long
    For i = 5 To 462
       With Range("D" & i).Validation
           .Delete
           .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
           xlBetween, Formula1:="=AU" & i & ":AX" & i & ""
           .IgnoreBlank = True
           .InCellDropdown = True
           .InputTitle = ""
           .ErrorTitle = ""
           .InputMessage = ""
           .ErrorMessage = ""
           .ShowInput = True
           .ShowError = True
       End With
    Next i
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Creating a macro to generate a list for hundreds of rows

    Hi kcgojnur,

    Try the following Macro. Changes in red. In most cases 'Select' is not needed, and causes Macros to run slowly.
    Sub CreateValidationList()
    
      Dim r As Range
      Dim iRow As Long
      Dim sFormula As String
      
      For Each r In Range("D5:D462")
        
        'Get the Row Number
        iRow = r.Row
        
        'Create the Formula (2 leading and trailing quotes allow quotes to be in the final formula)
        'Formula is of the Form: "=$AU$5:$AX$5"
        sFormula = "" & "=$AU$" & iRow & ":$AX$" & iRow & ""
    
        'Apply Data Validation
        With r.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
               xlBetween, Formula1:=sFormula
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
          End With
        
       Next r
       
    End Sub
    Lewis

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Creating a macro to generate a list for hundreds of rows

    
    Sub macro()
        With Range("D5:D462").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=$AU$5:$AX$5"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a macro to generate batch emails from a list of addresses in excel file
    By maccabarra in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2015, 02:59 PM
  2. Generate a list using macro
    By Unnati in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-08-2012, 04:07 AM
  3. how to apply a formula to hundreds of rows
    By Malkey in forum Excel General
    Replies: 11
    Last Post: 06-10-2012, 10:35 AM
  4. [SOLVED] Remove hundreds of empty rows
    By drews in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-22-2011, 04:29 PM
  5. Generate List of Matching Rows from multiple tabs
    By xenocide8d in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-02-2010, 12:52 AM
  6. Hide Hundreds of Rows
    By mavsman4457 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-14-2008, 12:53 AM
  7. [SOLVED] Need macro to generate list
    By Kristin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2006, 12:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1