+ Reply to Thread
Results 1 to 11 of 11

Dependant Data Validation and Relative Referrence in Macros

Hybrid View

DamienPalmer Dependant Data Validation and... 02-05-2014, 12:33 AM
:) Sixthsense :) Re: Dependant Data Validation... 02-05-2014, 12:51 AM
DamienPalmer Re: Dependant Data Validation... 02-05-2014, 01:07 AM
:) Sixthsense :) Re: Dependant Data Validation... 02-05-2014, 01:16 AM
DamienPalmer Re: Dependant Data Validation... 02-05-2014, 12:57 PM
DamienPalmer Re: Dependant Data Validation... 02-07-2014, 12:49 AM
FDibbins Re: Dependant Data Validation... 02-07-2014, 01:45 AM
DamienPalmer Re: Dependant Data Validation... 02-08-2014, 01:42 AM
  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Dependant Data Validation and Relative Referrence in Macros

    Hi,
    I am new to using Macros and data validation and have run into a problem i am hoping someone can help with.
    I am trying to create a macro for estimating purposes that will contain a dependent data validation. The dependent validation will work if i use a direct reference in the second validation
    =INDIRECT(SUBSTITUTE(I82," ","_"))
    This allows my second selection based on the first.
    The problem i have is i want this to run within a macro that can be inserted at any location in the sheet and so the I82 would need to be relative based on where i start. If i try
    =INDIRECT(SUBSTITUTE(R[-15]C," ","_"))
    I get an error as i am trying to run the macro.
    How would be the best way to achieve this?
    Thanks Damien

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Dependant Data Validation and Relative Referrence in Macros

    Hi DamienPalmer,

    Welcome to the forum

    Can you please share your full code?

    When you post code please Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    02-05-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Dependant Data Validation and Relative Referrence in Macros

    Hi Sixthsense,

    Thank you for the reply

    The code for the data validation is as follows

    ActiveCell.FormulaR1C1 = "Pedestals"
        ActiveCell.Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=INDIRECT(SUBSTITUTE(I82,"" "",""_""))"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = "Paver buildup"
            .ErrorTitle = ""
            .InputMessage = "Select build up type"
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    The I82 is a reference to the following data validation

    ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveCell.FormulaR1C1 = "Pedestal Base"
        ActiveCell.Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="Pedestal Base,Aggregate Base"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = "Geotextiles"
            .ErrorTitle = ""
            .InputMessage = "Select textile type"
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    The drop down list in the first code would change based on if aggregate base or pedestal base is selected from the menu set in the second code.
    I would need to change the I82 to reference 15 rows up no matter where i start the macro.

    Is this enough info, or do you need the code for the whole macro?

    Thanks

    Damien

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Dependant Data Validation and Relative Referrence in Macros

    Replace this

    "=INDIRECT(SUBSTITUTE("I82,"" "",""_""))"
    With

    "=INDIRECT(SUBSTITUTE(" & ActiveCell.Address & ","" "",""_""))"

  5. #5
    Registered User
    Join Date
    02-05-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Dependant Data Validation and Relative Referrence in Macros

    Hi Sixthsense,

    This is what i have now

    ActiveCell.Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=INDIRECT(SUBSTITUTE(" & ActiveCell.Address = "R[-15]C" & ","" "",""_""))"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = "Paver buildup"
            .ErrorTitle = ""
            .InputMessage = "Select build up type"
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    The macro will run but the dropdown menu just displays FALSE. This is the same is i enter cell reference I82 in place of the R[-15]C

    Damien

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Dependant Data Validation and Relative Referrence in Macros

    Delete this....

    "=INDIRECT(SUBSTITUTE(" & ActiveCell.Address = "R[-15]C" & ","" "",""_""))"

  7. #7
    Registered User
    Join Date
    02-05-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Dependant Data Validation and Relative Referrence in Macros

    Sorry, i thought i had put them in,


    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=INDIRECT(SUBSTITUTE(" & ActiveCell.Address & ","" "",""_""))"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = "Paver buildup"
    .ErrorTitle = ""
    .InputMessage = "Select build up type"
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
    End With

    When i try and run the macro it keeps giving me a Run-time error '1004'

    Damien
    Last edited by FDibbins; 02-07-2014 at 01:41 AM.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,047

    Re: Dependant Data Validation and Relative Referrence in Macros

    Damien, you actually did put them in, but you made a tiny error in syntax (no biggie, I have seen the same thing before)

    You had [CODE][/CODE] then your code, then ended with [CODE][/CODE]

    What you actually need is [CODE] your code [/CODE]
    Theeasy way to do it is paste in your code, highlight it, then click the # button above (where the "bold/Italic/underline" etc is
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  9. #9
    Registered User
    Join Date
    02-05-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Dependant Data Validation and Relative Referrence in Macros

    Hi Sixthsense,

    I have attached the excel sheet with how it should look. It will work if i put an absolute reference in an run it from the same starting cell but i cannot run it from any where. There are some notes on the sheet to explain. Hope this helps!

    Damien
    Attached Files Attached Files

+ 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. Dependant data validation with dependant default value
    By JamesMeek in forum Excel General
    Replies: 2
    Last Post: 04-08-2013, 10:16 AM
  2. dependant data validation
    By ztg5003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2011, 09:16 AM
  3. Dependant Data Validation
    By rhlongo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-05-2008, 12:32 PM
  4. Dependant? Data Validation
    By matrixskydiver in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-08-2007, 07:56 PM
  5. Dependant? Data Validation
    By matrixskydiver in forum Excel General
    Replies: 1
    Last Post: 12-08-2007, 08:10 AM

Tags for this Thread

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