How to associated a drop down macro to a new column

wzthxj

New Member
Joined
Mar 29, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have a workbook in which a new column has been added via the following:

Sub AddColumnsWithHeadersResize()

With Sheet4.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Resize(, 4)
.Value = Array("Observations", "Deviations", "Potential Debit Amount", "Debit Amount")
.Resize(, 1).ColumnWidth = 30
.Offset(, 1).Resize(, 1).ColumnWidth = 20
.Offset(, 2).Resize(, 2).ColumnWidth = 10
.Offset(, 2).Resize(, 2).ColumnWidth = 10
End With
End Sub

The new column "Deviations" will contain a drop down menu in each cell. I need to somehow associate the drop-down with this column, with the caveat that the number of columns before the 4 new ones just created varies by user. I created a macro but it's currently associated with a specific cell (which will change). Thanks for your help.

Range ("**").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Data!$A$2:$A$11"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How many cells do you want to put the validation into?
 
Upvote 0
4000. When I made the macro, I just clicked and dragged to copy it from the top cell downward.
 
Upvote 0
Ok, how about
VBA Code:
Sub wzthxj()
   
   With Sheet4.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Resize(, 4)
      .Value = Array("Observations", "Deviations", "Potential Debit Amount", "Debit Amount")
      .ColumnWidth = Array(30, 20, 10, 10)
      With .Offset(1, 1).Resize(4000, 1).Validation
         .Delete
         .Add xlValidateList, , , "=Data!$A$2:$A$11"
      End With
   End With
End Sub
I've added it to the previous code, so you can delete that.
 
Upvote 0
Solution
You are awesome! I was about to give up. Thank you so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top