• Use Ctrl Click to select non contIgous columns

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Use Ctrl Click to select non contIgous columns

    Author
    Topic
    #1774387

    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.

    Code:
    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

    Reply To: Use Ctrl Click to select non contIgous columns

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: