+ Reply to Thread
Results 1 to 3 of 3

Selecting cells using variables for row and column values

Hybrid View

moraym Selecting cells using... 08-05-2008, 06:19 AM
royUK Try this instead, it's... 08-05-2008, 06:43 AM
moraym No luck with that. I keep... 08-07-2008, 05:39 AM
  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    England
    Posts
    4

    Selecting cells using variables for row and column values

    What I'm trying to do is copy data from a horizontal list, paste it into a column on a different sheet and repeat until there is no more data to copy. The code shown is just a fragment.

    Do While Not IsEmpty(ActiveCell)
        Range("C[1st sheet row number here]:L[1st sheet row number]").Select
        Selection.Copy
        Sheets("Results").Select
        Range("[2nd sheet row],[2nd sheet column]").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, transpose:=True
        sr = sr + 1 [shifts 1st sheet down to next column]
        rr = rr + 10 [shifts 2nd down to end of data range]
    Loop
    Is this possible, or is there a better way?

    Thanks in advance!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this instead, it's untested but it should copy the Rows to successive columns in the other sheet

    Option Explicit
    
    Sub copyRowsToColumns()
        Dim R      As Long
        Dim C     As Long
        Dim X      As Long
        With Sheet1 'this is the data sheet, amend with corect name
            X = .UsedRange.Rows.Count
            For R = 2 To X 'assumes datra starts in Row2
                .Range(.Cells(R, 3), .Cells(R, 12)).Copy
                C = Sheets("Results").Cells(1, Columns.Count).End(xlToLeft).Column + 1
                Sheets("Results").Cells(1, C).PasteSpecial Paste:=xlPasteAll, _
                                                            Operation:=xlNone, SkipBlanks:= _
                                                            False, Transpose:=True
            Next R
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-25-2008
    Location
    England
    Posts
    4
    No luck with that. I keep getting object errors at this line:

    X = .UsedRange.Rows.Count
    Anyone have other ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1