0

I have an drop-down validating formuala for a cell and am using the generic formula inside the validation in vba.

Now, I want to automate it using the formula1 part inside the with loop here.

Here goes the Code,

Lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Lastrow2 = Sheets("Config").Cells(Rows.Count, "R").End(xlUp).Row
    For i = 2 To Lastrow
        With Range("M" & i).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, Formula1:="=Config!R2:R10"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
        End With
    Next

how would you replace the part in the code - Formula1:="=Config!R2:R10" with the 10 being Lastrow2.

Thanks

3
  • 4
    Formula1:="=Config!R2:R"&Lastrow2 Commented Aug 31, 2017 at 12:17
  • 1
    @Xire or Sid29, please post as an answer so this post can be marked as complete so it does not sit in the open-state indefinitely. Commented Aug 31, 2017 at 13:42
  • 1
    Xire's answer worked. So, if Xire can put that in the answer section, I will mark it as accepted :) Commented Aug 31, 2017 at 13:43

1 Answer 1

1

The solution :

Formula1:="=Config!R2:R"&Lastrow2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.