+ Reply to Thread
Results 1 to 3 of 3

Tweak code to copy range formatting too (instead of just copying values)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    353

    Tweak code to copy range formatting too (instead of just copying values)

    Hi all,
    Need some help in tweaking the below codes.
    Currently it is only copying the values from my "Data Source" sheeet.
    Can you help me modify it so that it copies the formatting as well?
    Sub Selection()
    Application.ScreenUpdating = False
    
    Dim cRng As Range, St As String, Cl As Range, Rng As Range
    With Sheets("By Site")
        St = .Range("VV8").Value
        Range("B32:P69").ClearContents
        Set cRng = Sheets("Data Source").Rows("160:160").SpecialCells(xlCellTypeConstants)
    
        For Each Cl In cRng
            If Cl = St Then
                Set Rng = Cl.Offset(, 2).CurrentRegion
                Rng.Offset(3).Resize(Rng.Rows.Count - 3).Copy
               .Range("B32").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            End If
        Next Cl
    End With
    End Sub
    I tried the below but no dice.

        .Range("B32").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
            , SkipBlanks:=False, Transpose:=False
    Thank you in advance.
    Last edited by Andrew.Trevayne; 02-04-2017 at 03:01 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,708

    Re: Tweak code to copy range formatting too (instead of just copying values)

    Perhaps
            If Cl = St Then
                Set Rng = Cl.Offset(, 2).CurrentRegion
                Rng.Offset(3).Resize(Rng.Rows.Count - 3).Copy
               .Range("B32").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            End If
    to
            If Cl = St Then
                Set Rng = Cl.Offset(, 2).CurrentRegion
                Rng.Offset(3).Resize(Rng.Rows.Count - 3).Copy .Range("B32")
            End If

  3. #3
    Forum Contributor
    Join Date
    11-02-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2003
    Posts
    353

    Re: Tweak code to copy range formatting too (instead of just copying values)

    Quote Originally Posted by jindon View Post
    Perhaps
            If Cl = St Then
                Set Rng = Cl.Offset(, 2).CurrentRegion
                Rng.Offset(3).Resize(Rng.Rows.Count - 3).Copy
               .Range("B32").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            End If
    to
            If Cl = St Then
                Set Rng = Cl.Offset(, 2).CurrentRegion
                Rng.Offset(3).Resize(Rng.Rows.Count - 3).Copy .Range("B32")
            End If

    Thank you sir. Working perfectly.

+ 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. Tweak to VBA code for copying from Excel into Powerpoint
    By benoj2005 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2016, 09:44 AM
  2. [SOLVED] Tweak my code so it does not copy rows that are in the shaded area
    By Roco in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2016, 03:15 AM
  3. [SOLVED] Copy range values without copying the formatting
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 08:13 AM
  4. Code tweak needed: Copy macro not copying formats only values (with getobject)
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-19-2012, 01:06 PM
  5. Copying Values and Formatting without Copy/PasteSpecial
    By bungeejumper2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2012, 04:26 PM
  6. Copy Table Code - Tweak
    By SamuelT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2010, 10:58 AM
  7. code tweak to copy data from sheet1 to sheet2
    By imatomic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2010, 02:18 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