Set validation properties of one cell to those of another in Visual Basic

medberg

New Member
Joined
Jul 29, 2011
Messages
30
Hello,

Right now I have a bunch of cells in a table with certain data validation properties. All of the cells of a particular column in the table have the same properties. My issue is, the whole table minus the header gets deleted then restored in my VB code. When this happens, the restored cells no longer have the validation properties they need. So what I was thinking was to take the validation properties of the headers of each table column, and extend them to the entire column (because the header of the table never loses it's validation properties). So my code looks like this:

Code:
Dim upperLeftC As Long
Dim upperLeftR As Long
Dim rowC As Long
rowC = Sheet1.ListObjects(1).ListColumns.Count
upperLeftC = Range(Sheet1.ListObjects(1).Range.Cells(1).Address(0, 0)).Column
upperLeftR = Range(Sheet1.ListObjects(1).Range.Cells(1).Address(0, 0)).Row
Dim counter As Long
For counter = upperLeftC To upperLeftC + rowC - 1
Columns(counter).Select
Selection.Validation = Sheet1.Cells(upperLeftR, counter).Validation
Next counter
End Sub

The problem is the line:

Code:
Selection.Validation = Sheet1.Cells(upperLeftR, counter).Validation

This line does not work at all and I knew it wouldn't, but I can't find anywhere what to replace it with. Thanks in advance! :rolleyes:
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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