+ Reply to Thread
Results 1 to 3 of 3

Help with my code - I want to clear any formulas when pasting

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    18

    Help with my code - I want to clear any formulas when pasting

    Hello

    I have some code which works really well:-

    Option Explicit
    
    Dim s1rw As Long, s2rw As Long, col As Long, endcol As Long
    Cancel = True ' Ignore error messages as first column is LOCKED
    Sheets("Page2").Select
    
    With Sheets("Page1")
        s2rw = 3 ' Adjust to first data row #
        endcol = .Cells(s2rw - 1, 1).End(xlToRight).Column
        Do Until .Cells(s2rw, 1).Value = "" ' Loop through case #s
            s1rw = 0
            On Error Resume Next
            s1rw = Cells.Find(What:=.Cells(s2rw, 1).Value, LookIn:=xlFormulas, LookAt:=xlWhole).Row
            On Error GoTo 0
            
            If s1rw > 0 Then ' Found case #
                For col = 2 To endcol ' Loop through columns
                    If Cells(s1rw, col).Value <> "" Then
                        If IsDate(Cells(s1rw, col).Value) Then
                            .Cells(s2rw, col).Value = Format(Cells(s1rw, col).Value, "mm/dd/yyyy")
                        Else
                            .Cells(s2rw, col).Value = Cells(s1rw, col).Value
                        End If
                    End If
                Next
            End If
            s2rw = s2rw + 1
        Loop
        .Select
    End With
    However in page 1 I sometimes have formulas. I want my in page2 to copy over and clear the formula as the formula is then changing the pasted data.

    Can anyone please help!!
    Last edited by JBeaucaire; 03-03-2015 at 11:03 AM.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Help with my code - I want to clear any formulas when pasting

    You want the formula pasted into sheet two, calculated THEN copy+paste values?
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,155

    Re: Help with my code - I want to clear any formulas when pasting

    Why not just make a (full) copy of the source sheet, complete with formulae, then select all the cells and Copy and Paste Special | Values? Then you have an exact copy of the source data with no formulae, just values. And then do whatever processing is required on the target sheet with the values.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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] Clear All VBA Codes and formulas
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-03-2014, 04:04 PM
  2. [SOLVED] Noob using marco, I need to clear what my previous macro copied before pasting my new one
    By Slinky84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2014, 01:35 PM
  3. Code is pasting formulas instead of values - Please help
    By ByronHopf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2014, 08:25 PM
  4. Clear static formulas, but leave linked formulas
    By pacerx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2013, 05:08 AM
  5. Replies: 3
    Last Post: 03-26-2005, 11:06 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