+ Reply to Thread
Results 1 to 7 of 7

How to copy data from one column to other column using VBA

  1. #1
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    How to copy data from one column to other column using VBA

    Hello,

    I am looking for a VBA solution to ease my routine work in the following scenario.

    1.The output from web query is loaded into "Master" Sheet.
    2. In "Raw Data" sheet I used x lookup formula to get the required data for each column header from the "Master sheet"

    What I want in "Raw Data" sheet is to copy the data from xlookup formula column and paste as values in the next cells every time I run the web query with new date. This I want to do for a max period of 22 days.

    I am herewith attaching the excel file wherein I have created 22 blank columns for each header data in "Raw Data" Sheet highlighted in yellow color. I want to copy the data to adjacent column for each header in the master sheet.

    Any help is much appreciated.

    Thank you
    Attached Files Attached Files
    Last edited by zaska; 05-01-2023 at 08:36 PM.

  2. #2
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to copy data from one column to other column using VBA

    Can anyone help to solve the problem?

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    According to your attachment a VBA demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
        
    With Sheets("RawData").UsedRange.Rows
            With 
    .Item("3:" & .Count).Columns
            
    For C% = 2 To 255 Step 23
                
    If IsEmpty(.Cells(122)) Then .Item(.Cells(122).End(xlToLeft)(12).Column) = .Item(C).Value
            Next
            End With
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: Hello, try this !

    Quote Originally Posted by Marc L View Post

    According to your attachment a VBA demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
        
    With Sheets("RawData").UsedRange.Rows
            With 
    .Item("3:" & .Count).Columns
            
    For C% = 2 To 255 Step 23
                
    If IsEmpty(.Cells(122)) Then .Item(.Cells(122).End(xlToLeft)(12).Column) = .Item(C).Value
            Next
            End With
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Thank you for the code. Once all the 22 columns are filled there are no empty columns. How to accomadate the new data in the first column so that I always have 22 days of data with new data updated

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy data from one column to other column using VBA


    As the new data are updated via a XLOOKUP formula - so nothing to do ! - or
    it depends on what you really need which does not seem to match with this thread subject …
    Anyway thanks for the rep' !

  6. #6
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to copy data from one column to other column using VBA

    I ran the code for 22 days i.e 22 times so all the 22 columns got filled. Now for the 23rd day I have new data in the xlookup formula column. As there are no empty cells now the code will exit.

    What I want to do is to copy the new data to the next column so that the data gets shifted to the next column rewriting the old data in column 22

    Thank you.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy data from one column to other column using VBA


    Add an Else to the condition in order to copy the data where you want …

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Query table, retain the column names on refresh
    By Stefan22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2018, 07:06 PM
  2. Copy data from sheet1 column with dynamic date, and copy data to second sheet column
    By Renaliiii in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2016, 04:44 PM
  3. Replies: 5
    Last Post: 11-17-2014, 02:40 PM
  4. Replies: 2
    Last Post: 09-29-2013, 06:15 AM
  5. Replies: 1
    Last Post: 09-28-2013, 07:11 PM
  6. Replies: 3
    Last Post: 05-22-2013, 01:08 AM
  7. Copy data from column K to column B if Column C and column I match
    By goog2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2013, 12:19 PM

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