+ Reply to Thread
Results 1 to 5 of 5

Thread: Copying formulas, not links or just data

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    Copying formulas, not links or just data

    Hi all,

    Title seems quite simple, pretty much because it is :P

    Ive got this code (kindly figured out by snb):
    Sub Update_Click()
    
    For Each tb In Sheet1.CheckBoxes
       With tb.TopLeftCell
         If tb = 1 Then
         
            If .Row = 1 Then Sheets("Sheet2").Cells(1, .Column).Resize(Sheet2.UsedRange.Rows.Count) = Sheet1.UsedRange.Columns(.Column).Value
            If .Column = 1 Then Sheets("Sheet2").Cells(.Column, 1).Resize(Sheet2.UsedRange.Columns.Count) = Sheet1.UsedRange.Rows(.Row).Value
            
         Else
         
            If .Row = 1 Then Sheets("Sheet2").Columns(.Column).ClearContents
            If .Column = 1 Then Sheets("Sheet2").Rows(.Row).ClearContents
        End If
       End With
      Next
    End Sub
    And i would like to copy the formula in the cells as well as the data. so then the user can use the new spreadsheet as a stand alone sheet, with out the data being linked to the other sheet.

    Any help would be very much appreciated

    Thanks,
    Storm08
    Last edited by Storm08; 01-27-2012 at 06:35 AM.

  2. #2
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Copying formulas, not links

    Hi,

    You need to use the paste-special command - something along these lines:

    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
    Just use that code on the cell you're copying and it will only paste the formula,

    Does that help?

    - Jon

  3. #3
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Copying formulas, not links

    hello

    That is somewhat helpful but how would I incorporate that into this line of code?:

    If .Row = 1 Then Sheets("Sheet2").Cells(1, .Column).Resize(Sheet2.UsedRange.Rows.Count) = Sheet1.UsedRange.Columns(.Column).Value

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Copying formulas, not links or just data

    Sub Update_Click()

    For Each tb In Sheet1.CheckBoxes
       With tb.TopLeftCell
         If tb = 1 Then
         
            If .Row = 1 Then Sheets("Sheet2").Cells(1, .Column).Resize(Sheet2.UsedRange.Rows.Count).formula = Sheet1.UsedRange.Columns(.Column).formula
            If .Column = 1 Then Sheets("Sheet2").Cells(.Column, 1).Resize(Sheet2.UsedRange.Columns.Count).formula = Sheet1.UsedRange.Rows(.Row).Formula
            
         Else
         
            If .Row = 1 Then Sheets("Sheet2").Columns(.Column).ClearContents
            If .Column = 1 Then Sheets("Sheet2").Rows(.Row).ClearContents
        End If
       End With
      Next
    End Sub



  5. #5
    Registered User
    Join Date
    01-12-2012
    Location
    Aylesbury
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Copying formulas, not links or just data

    snb, cant thank you enough I probably should have seen that one! -_- oh well, gotta keep learning i suppose. thanks very much, your code has taught me well

+ 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.2.0