+ Reply to Thread
Results 1 to 6 of 6

How to copy the cell which has formula

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    12

    How to copy the cell which has formula

    Hi,

    How to copy the cell which has formula by using macro

    * I need to copy the 1500 cells in one column and paste into multiple times [20]

    Attached sheet for referance...

    1.The sheet is opening with 16 column
    2.If i give input as 20, further 4 columns to be added [ Not affecting the column 'U' ]

    Please guide me to solve the same.

    -Sugavanam
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to copy the cell which has formula

    You can record a macro doing this....

    menubar/edit/goto.../formulas



  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: How to copy the cell which has formula

    You can use this code. I have tested it, complete with the inputbox and even the columns get numbered accordingly.

    Sub insert_cols()
    
    lastcol = Range("A1").End(xlToRight).Value
    
    If lastcol = "Total No" Then
    
        lastcol = Range("A1").End(xlToRight).Offset(0, -1).Value
        Range("A1").End(xlToRight).Select
        coladd = Left(ActiveCell.Address(1, 0), InStr(1, ActiveCell.Address(1, 0), "$") - 1)
        colprev = Left(ActiveCell.Offset(0, -1).Address(1, 0), InStr(1, ActiveCell.Offset(0, -1).Address(1, 0), "$") - 1)
    
    End If
    
    userno = InputBox("Please provide the total number of columns required")
    
    coldiff = userno - lastcol
    
    For i = 1 To coldiff
    
        Columns(colprev & ":" & colprev).Copy
        Columns(coladd & ":" & coladd).Select
        Selection.Insert shift:=xlToRight
        lastcol = lastcol + 1
        Range(coladd & "1").Value = Range(colprev & "1").Value + 1
        colprev = coladd
        coladd = Left(ActiveCell.Offset(0, 1).Address(1, 0), InStr(1, ActiveCell.Offset(0, 1).Address(1, 0), "$") - 1)
        
    Next
    
    End Sub


    Thanks,
    Arlette Aloysius

    If this was useful then please rate it appropriately.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to copy the cell which has formula

    Try this workbook

    Run the macro "ColsRequired"
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: How to copy the cell which has formula

    Marcol,

    I have also tested the code you provided to see on how i can better my code. I observed that your code doesnt copy the formulae across to the new columns. That is what sugavanam wants.

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to copy the cell which has formula

    The question is, what formula?

    If you are refering to =SUM(D4:R4), originally in T4, then I don't see the logic in this remaining unchanged if columns are added, as Column T is "Total No" surely this should total the row? ...

    My logic says that this should actually be =SUM(D4:S4).

    Not affecting the column 'U'
    Column U doesn't have a formula, do you think sugavanam means Column T should remain unchanged?

    Check the formula I have in "Total No" after you run the code.

    P.S. the only other formulae I can see are =I552*#REF! and =J552*T560 in columns I & J, they look like mistakes to me.

    For your benefit look at these rows of code as a way to avoid loops
            .Range("D1:E1").AutoFill rngNew, xlFillSeries
            .Cells(3, TotalColsRqd + 3 + 1).Resize(LastRow - 3, 1).Formula = "=SUM(" & rngNew.Offset(2, 0).Address(0, 0) & ")"

+ 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