1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: macro to copy to next empty column

Discussion in 'Business Applications' started by costagin, Apr 15, 2010.

Thread Status:
Not open for further replies.
  1. costagin

    costagin Thread Starter

    Joined:
    Apr 15, 2010
    Messages:
    8
    My operating system is XP Professional
    I'm using Excel 2002

    I'm trying to create a macro to copy a column of data from cells C3:C23 and paste it into a range of columns starting with O13:O33 and ending with Z13:Z33. Each time I run the macro I want it to advance to the next empty column and PasteSpecial, ValuesOnly in that column. After all 12 columns have data in them, the next time the macro runs it has to delete all twelve columns and start over at the first column O13:O33.

    The following is what I have done but it only pastes into the first column and never advances to the next one.

    Range("C3:C23").Select
    Selection.Copy
    Range("O13").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("A1").Select

    Thanks for your help.

    costagin
     
  2. Ent

    Ent Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,467
    First Name:
    Josiah
    I think that this is what you need.

    Code:
    Dim ColCount As Integer
    Dim RowClear As Boolean
    ColCount = 0
    RowClear = False
    
    Do
    ColCount = ColCount + 1
    RowClear = True
    
    For r = 13 To 33
    If Cells(r, ColCount + 14).Value <> 0 Then RowClear = False
    Next r
    
    Cells(1, 1).Value = RowClear
    Cells(1, 2).Value = ColCount
    Loop Until ColCount = 13 Or RowClear = True
    
    If ColCount = 13 Then
    ColCount = 1
    Range("O13", "Z33").ClearContents
    End If
    
    For r = 3 To 23
    Cells(r + 10, 14 + ColCount).Value = Cells(r, 3).Value
    Next r
    
     
  3. costagin

    costagin Thread Starter

    Joined:
    Apr 15, 2010
    Messages:
    8
    Thank you very much. It works perfectly. I really appreciate your help.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/917192

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice