Results 1 to 5 of 5

Thread: [RESOLVED] Prevent drop down list from moving when column deleted.

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    12

    Resolved [RESOLVED] Prevent drop down list from moving when column deleted.

    I have a spreadsheet that has a few drop down lists. The problem I will encounter is when data is pasted onto a tab, said data will fill columns A-J, columns A & B will be deleted, thus the last header will be in column H, as it should. My drop down code works, but moves when columns A and B are deleted. Is there a way to prevent this?


    Code:
    Sub CreateDV()
    With Range("$H$2:$H$50").Validation
      .Delete
      .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
      xlBetween, Formula1:="Yes,No"
      .IgnoreBlank = True
      .InCellDropdown = True
      .InputTitle = ""
      .ErrorTitle = ""
      .InputMessage = ""
      .ErrorMessage = ""
      .ShowInput = True
      .ShowError = True
    End With
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Prevent drop down list from moving when column deleted.

    if you put it in column j, will it move to the correct location?
    can you add the drop down after the first 2 rows are removed?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    12

    Re: Prevent drop down list from moving when column deleted.

    Yes it will be in the correct position after columns are deleted, but not everyone will do it the same. I for instance delete the columns on a separate spreadsheet then paste into the working tab.

    What about using find() to find a header name? Could I put that in?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Prevent drop down list from moving when column deleted.

    What about using find() to find a header name? Could I put that in?
    of course
    or last column with data
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    12

    Re: Prevent drop down list from moving when column deleted.

    I controlled this with a conditional statement, which worked out well.

Posting Permissions

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



Click Here to Expand Forum to Full Width