+ Reply to Thread
Results 1 to 15 of 15

VBA to copy range from one column to other

  1. #1
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    VBA to copy range from one column to other

    Hi I have a Table in Sheet Item.

    The table range may start from any cell in the sheet.

    Hence i need a code to perform below task.

    First find non blank cell in sheet "Item"
    Copy the column till the last row, go to last column and +1 and paste.
    Give 2 headings "% of claims" and "% of amount"
    Calculate some formula in next columns.

    I have given the required result in Sheet along with required formula "Result after code"

    Please help
    Attached Files Attached Files

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    Try this

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

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

    Cool Hi ! Try this !


    According to your attachment as a starter :

    PHP Code: 
    Sub Demo1()
        
    With Sheets("items").UsedRange.Find("Amount", , xlValuesxlWholexlByRows).CurrentRegion.Columns
                  Union
    (.Item(1), .Item(3)).Copy .Range("E1")
                 .
    Range("A1:B1").Copy .Range("G1")
                 .
    Range("G1:H1").Value2 = [{"% of Claims","% of amount"}]
            
    With .Item("G:H").Rows("2:" & .Rows.Count)
                 .
    Borders.Weight xlThin
                 
    .NumberFormat "0.00%_w"
                 
    .Formula "=" & .Cells(1, -4).Address(FalseFalse) & "/" & .Cells(.Count, -4).Address(, False)
                 .
    Formula = .Value2
                 
    .Item(.Count).Font.Bold True
            End With
                 
    .Item("E:H").AutoFit
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-15-2019 at 07:32 PM. Reason: optimization …

  4. #4
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Hi ! Try this !

    Hi,
    Here range is defined in a code.

    I my data the data starting cell will differ every time.

  5. #5
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to copy range from one column to other

    Hi,
    it is not copying Item and No. of Claims.

    Required result is same as in sheet "Result after code"

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

    Arrow

    Quote Originally Posted by saravanan1981 View Post
    Here range is defined in a code.
    Nope in both codes ‼ At least try before …

    Quote Originally Posted by saravanan1981 View Post
    it is not copying Item and No. of Claims.

    Required result is same as in sheet "Result after code"
    As my demonstration returns exacly the expected result, again just try before !

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    Quote Originally Posted by saravanan1981 View Post
    Hi,
    it is not copying Item and No. of Claims.

    Required result is same as in sheet "Result after code"
    Your example did not show number of claims being copied, only columns 1 and 3 of origiinal table was copied.
    Last edited by JLGWhiz; 08-16-2019 at 12:31 PM.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    See if this is more to your liking.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to copy range from one column to other

    Hi JLGWhiz,
    Its Simply Superb.


    I just need one more help on the same code.

    While copying to new column, do not copy "No. of Claims" (I know I have asked for it earlier. But now no need). Also heading format of % Claims and % Amount
    to be same as other hadings. Also the multiplication formula should be vissible instead of values.

    Simply I want the result same as "Result after code".

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

    Arrow

    Quote Originally Posted by saravanan1981 View Post
    Simply I want the result same as "Result after code".
    According to your attachment you already had it since post #3 ‼

  11. #11
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    Quote Originally Posted by saravanan1981 View Post
    Hi JLGWhiz,
    Its Simply Superb.


    I just need one more help on the same code.

    While copying to new column, do not copy "No. of Claims" (I know I have asked for it earlier. But now no need). Also heading format of % Claims and % Amount
    to be same as other hadings. Also the multiplication formula should be vissible instead of values.

    Simply I want the result same as "Result after code".
    If you are going to use formulas, then there is not much point in using VBA. The code provided does the same task as the formulas and leaves the Sheet unincumbered by the formulas, thereby reducing the probability that someone will inadvertantly change or delete the formulas through editing.

  12. #12
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    Here is all execept the formulas.

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to copy range from one column to other

    Hi JLGWhiz,

    Thanks a ton for your help.

  14. #14
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to copy range from one column to other

    You are welcome,
    Regards, JLG

  15. #15
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: VBA to copy range from one column to other

    Hi JLGWhiz,

    Just wanted to check, It that possible to add one more column, as mentioned in Column K. if the amount is less than lakh, amount should be converted into numbers as mentioned in K11.
    If the amout is grater than lakhs, it should convert in 2 decimal like as mentioned in K12. If it is more than 1 crore than mount should converted to 2 decimal as mentioned in K7.

    In such way i wanted to make a sentence in column K.

    I dont know whether it is possible or nor. Please advise.
    Attached Files Attached Files
    Last edited by saravanan1981; 08-18-2019 at 09:55 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. Filter range, copy range (not entire column), paste in another worksheet
    By LukeNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2018, 08:28 AM
  2. [SOLVED] Button to Copy Column Range with ActiveCell position, Losing formatting after 3rd column
    By xlyfe in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-16-2018, 03:42 PM
  3. VBA Excel: Copy/Paste a column range to another sheet IF column headers match
    By hwatson86 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-07-2016, 08:05 AM
  4. loop through range to copy row if data exists in column, then delete the column
    By wpryan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2015, 05:03 PM
  5. [SOLVED] Copy and paste values in column range into first empty column to the left
    By gbatz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2014, 06:59 PM
  6. Match values in a range with another range and copy the adjacent column
    By xelmac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2012, 01:42 PM
  7. Macro broken - copy data range column to empty data range column
    By Cascus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-06-2011, 05:20 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