+ Reply to Thread
Results 1 to 3 of 3

Using macro to do same task with different cells

  1. #1
    Registered User
    Join Date
    09-26-2005
    Posts
    2

    Using macro to do same task with different cells

    I m new to Excel VBA, i have a worksheet in which i want to select 7 cells in a coloumn and then paste in a row. Then i again want to copy 7 next cells and paste then in next row. I m trying to use DO UNTIL LOOP, and using following code

    Sub copypaste1()
    1 Dim k,i
    2 For i = 1 To 1520
    3 Do Until i = 1520
    4 k = (i + 8) + (6 * (i - 1)) '' k=9,16,23,30
    5 Range("B(k):B(k+6)").Select
    6 Selection.Copy
    7 Range("F(i+6)").Select
    8 Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    9 Loop
    10 Next
    End Sub

    but at line 5, "Method 'Range' of object '_Global' failed" error appeared. I think there is some problem in the way i am selecting the cell range, any soln?

  2. #2
    Registered User
    Join Date
    09-16-2005
    Location
    Bangalore, India
    Posts
    47
    Try this

    Sub copypaste1()
    Dim K as Integer, I as Integer
    For i = 1 To 1520
    Do
    K = (I + 8) + (6 * (I - 1)) '' k=9,16,23,30
    Range(Cells(K,2),Cells(K+6,2)).Select
    Selection.Copy
    Cells(I+6, 6).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    Loop Until i = 1520
    Next
    End Sub

  3. #3
    Registered User
    Join Date
    09-26-2005
    Posts
    2
    Little modification still required,
    I have to remove DO UNTIL loop and then it starts working
    anyhow, Thanks

+ 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