+ Reply to Thread
Results 1 to 12 of 12

Copy data column wise to new sheet with code

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Copy data column wise to new sheet with code

    Hello Experts
    I have written the code to create a new sheet along with headings. I am trying to copy the data from the source sheet (Consolidated) to the destination sheet (Sales) in some columns and insert formulas in some with the help of a code. I have written the beginning and end of the code as required, but I am not able to write the code to copy the data and resize the rows of destination sheet with the source sheet. I would really appreciate if someone can help me to get at least the first column then I can get the rest of the columns. The main problem is defining the variable and resizing the data.
    Thank you in advance.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 03-30-2023 at 12:59 AM. Reason: #Solved by John Topley

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Copy data column wise to new sheet with code

    Please Login or Register  to view this content.

    Try the above
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    Thanks John Topley. The data is copied successfully but it is too difficult to understand the code. Can you please comment the code at each line ? Especially this line
    Dim c As Long, cc As Long, r As Long, clr As Integer, icol

    what does the 0 in this line mean ?
    icol = Array(1, 2, 3, 4, 8, 9, 11, 13, 14, 15, 16, 18, 20, 22, 24, 0, 25, 26)

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    I have some lines above in the code which are not yet defined. If you please write the line like this for me, it will be easier to understand and learn.
    Dim lastRow As Long
    Dim OutputArray As Variant
    Dim LastRowSales As Long
    Dim LastRowconsolidated As Long

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Copy data column wise to new sheet with code

    You have seen this type of code before ....

    ICOL is an array of the column numbers in "Consolidated" from where the data is to be extracted. the zero (o) relates to the column for "Rate %" which does NOT appear in "Consolidated" so the data extract is "skipped" if any ICOL value is zero.

    CC is the column count relating the columns in "Sales"

    You don't know what this line is ....

    Dim c As Long, cc As Long, r As Long, clr As Integer, icol

    It is simply a Dimension statement (declaration of the attributes of a variable) with multiple entries rather than writing individual lines

    Dim c As Long
    Dim cc As Long...... etc


    Ditto

    Dim lastRow As Long
    Dim OutputArray As Variant
    Dim LastRowSales As Long
    Dim LastRowconsolidated As Long

    You do not appear to have made much progress if you do understand these basic constructs of VBA.

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    I agree with you that I am poor at the basics. I create codes which are similar with the help of comments in the codes shared. If there are no comments it is not possible for me to understand and edit them. I have been busy understand the codes which are connected to accounts only. You are right. Once I learn and make my basics strong, I will be able to write codes on my own.
    Thanks for the brief explanation. I will try to complete the rest of the code now.

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Copy data column wise to new sheet with code

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    Please Login or Register  to view this content.
    John, Please help me to correct the formula for column S. The other columns are working.

  9. #9
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    Thanks for the comments John Topley. This will be really very helpful. If you can correct the column S code, then I can add some more lines and format the columns as required.

  10. #10
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    Hello, I have completed the rest of the code. If the column S formula code is corrected then the first stage of this project will be over. Timr for me to hit the sack now. See you tomorrow.. Sharing the updated file.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Copy data column wise to new sheet with code

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Copy data column wise to new sheet with code

    Good Morning John Topley. Thank you very much for the code and helping me to correct the formula.
    I tried to give rep, but once again I am getting the same message. Wonder what it means....
    rep.png
    Last edited by RAJESH SHAH; 03-30-2023 at 01:01 AM.

+ 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. [SOLVED] Converting dynamic data from Column wise to Row wise format.
    By thebeastslayer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-29-2020, 07:25 AM
  2. Replies: 4
    Last Post: 05-01-2020, 01:10 AM
  3. [SOLVED] need to arrange column wise data to row wise with monthly wise
    By alok.gupta4ever in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2016, 11:11 AM
  4. Copy column data value date wise
    By tohel in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-15-2016, 04:52 AM
  5. Copy row wise data into a merged cell from sheet 1 to sheet2
    By friendlykashish in forum Excel General
    Replies: 8
    Last Post: 11-25-2014, 09:12 PM
  6. Excel code to represent data from row wise to column wise
    By sreejeshc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-12-2013, 03:45 AM
  7. Replies: 4
    Last Post: 08-01-2012, 09:50 AM

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