How to automatically select a non-consecutive range of rows/columns

0

I have an Excel document in which I want to select a few hundred rows (not necessarily consecutive), in order to then copy them into another document (which will incidentally serve as a source document for a Word address label document).

I have everything figured out regarding how to do this, except for the first part: selecting the appropriate rows.

Is there some dialog somewhere in which I can input a string such as "1-5, 7, 9-13, 24-28, 33", whereupon the indicated rows are selected? Or do I have to use some kind of macro?

EDIT: Note that what I'm after is a regular selection. I want to "automate" the arduous process of CTRL-clicking column after column in order to achieve the desired selection.

andreasdr

Posted 2014-08-14T11:15:50.567

Reputation: 103

Is this a recurring or one time task? What version of Excel are you using? – CharlieRB – 2014-08-14T11:53:17.430

Do you mean, some times you want to copy columns only, and some times only rows only and not a combination or rows and columns? – Dave – 2014-08-14T12:35:40.187

Answers

1

This should do it for you, assuming that (in the code below) A1 is where you'll put the data.

Please note, it will accept numbers as rows, strings as columns

Option Explicit
Sub HighlightAllSortsOfMadness()

Dim values() As String

values = Split(Range("A1").Value, ",") 'A1 is rows and columns you specify, such as 1,4,6,7,B,D . Separate each with a comma, 


Dim result As String

Dim i As Integer

    For i = 0 To UBound(values)
        If values(i) = "" Then
            Exit For
        End If

    result = result & values(i) & ":" & values(i) & ","

    Next i

    Range(Left(result, Len(result) - 1)).Select

End Sub

Before

enter image description here

And after I run the macro

enter image description here

Dave

Posted 2014-08-14T11:15:50.567

Reputation: 24 199

0

If you know the letters/numbers, you can select them with a simple formula: =B:B;D:D;G:G;I:I;K:K;N:P;

B:B will select entire column. N:P will select entire columns form N to P, included.

edumgui

Posted 2014-08-14T11:15:50.567

Reputation: 546

This looks a bit like what I want to do. But where am I to input this formula, and how do I copy the contents of the indicated columns so that I can paste it into another document?

Note that what I'm after is a regular selection, not a cell reference. I want to "automate" the arduous process of CTRL-clicking column after column in order to achieve the desired selection. – andreasdr – 2014-08-14T12:17:13.303

Manually, in the new sheet (or workbook), select A1 and input the formula =[Contacts.xlsx]Sheet1!A:A. For doing it automatically, you'll need a macro/vba script, I'm sure you'll be able to do it with a little how to: http://www.ozgrid.com/forum/showthread.php?t=58648

– edumgui – 2014-08-14T12:40:08.663