I am trying to write a VBA routine that will allow the user to select non contagious columns. The problem is at the start I do not know how many columns will need to be selected. I could step through the procedure one at a time but would prefer to select them all first.
I have tried using the union function in a very clumsy fashion. The example code below skips if 3 columns are not selected and goes to 2 of course if I had not selected 2 columns I would have an error. I could expand the lines that create the union and skip past each one on error but that is where clumsy comes in.
Sub ctrlselect() Dim ColS(), Y, Check Y = 0 Do Until Check = vbNo Y = Y + 1 ReDim Preserve ColS(Y) Set Col1 = Application.InputBox(“Select Cell in Column”, Type:=8) ColS(Y) = Col1.Column Check = MsgBox(“Any More Columns”, vbYesNo) Loop On Error Resume Next Application.Union(Columns(ColS(1)), Columns(ColS(2)), Columns(ColS(3))).Select Application.Union(Columns(ColS(1)), Columns(ColS(2))).Select End Sub
Thanks for any suggestions, I am working on a Mac so its really cmd+click