+ Reply to Thread
Results 1 to 17 of 17

assistance on paste special formats vba code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    assistance on paste special formats vba code

    Copying formats from sheets workings (template) to consolidation data sheet in same range as per code is ok.as below

    However how to paste specials format only from RANGE (h2:v2) to last data row in sheet consolidation data

    there is data from g1 still to last data row




    
    Sub format_inte_pastespecialformat()
    
    
    
    'Sheets("WORKINGS").Range("H2:V2").copy
    
    'Sheets("consolidation DATA").Range("H2:V2").PasteSpecial Paste:=xlPasteFormats
    
    End Sub

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: assistance on paste special formats vba code

    Hi JEAN1972

    Do you want to copy from range("H2:V2")
    to Range("G") and next available row?
    Sub format_inte_pastespecialformat()
    Dim nextRow As Long
    nextRow = Sheets("consolidation DATA").Range("G" & Rows.Count).End(xlUp).Row + 1
    Sheets("WORKINGS").Range("H2:V2").Copy
    Sheets("consolidation DATA").Range("G" & nextRow).PasteSpecial Paste:=xlPasteFormats
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    Hi Sinetek


    range g the column where data starts at rows 2 the range h2 to V2 IN COLOUR up to last data row

    Not giving expected results , the code is format the last row of data.
    See attached workings row 2 the range format is the colour format,

    my code copies from from workings to consolidation data

    what i expect is copy the colour format only from consolidation row 2 range and paste to last data row as G has data in it .

    If it could copy directly from workings it and paste special directly in the range of consolidation

    RANGE H2 TO V2 COPY COLOUR FORMAT ONLY TO LAST DATA ROW AS REFERENCE COLUMN G2 TO LAST DATA row as per consolidation data jpeg
    Attached Images Attached Images
    Last edited by JEAN1972; 05-03-2017 at 04:25 PM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    Sub format_inte_pastespecialformat()
    
    
    
    Sheets("WORKINGS").Range("H2:V2").Copy
    
    Sheets("consolidation DATA").Range("G1").Resize(Range("G" & Rows.Count).End(xlUp).Row).PasteSpecial Paste:=xlPasteFormats
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    Hi AB33

    Not giving expected results the actual code highlights in green columns G

    As per explanation and jpegs

  6. #6
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    as per jpeg expected results of consolidation data pastespecials format only
    Attached Images Attached Images

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    It is a guess work. Which columns and rows do you want to format in sheet consolidation?

    It could be one of these

    Sub format_inte_pastespecialformat()
    
    Dim LR As Long, LC As Long
    LR = Sheets("consolidation DATA").Range("G" & Rows.Count).End(xlUp).Row
    LC = Sheets("consolidation DATA").Cells(1, Columns.Count).End(xlToLeft).Column
    Sheets("WORKINGS").Range("H2:V2").Copy
    
    Sheets("consolidation DATA").Range("G1").Resize(LR, LC).PasteSpecial Paste:=xlPasteFormats
    
    End Sub
    
    Sub format_inte_pastespecialformatAm()
    
    Dim LC As Long
    LC = Sheets("consolidation DATA").Cells(1, Columns.Count).End(xlToLeft).Column
    Sheets("WORKINGS").Range("H2:V2").Copy
    
    Sheets("consolidation DATA").Range("G1").Resize(, LC).PasteSpecial Paste:=xlPasteFormats
    
    End Sub

  8. #8
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    Code not giving expected results

    See condensed sample with expected results sheets
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    This might work on the actual data.

    Sub format_inte_pastespecialformat()
    
    Dim LR As Long, LC As Long, ms As Worksheet
    
    Set ms = Sheets("consolidation DATA")
    
    With ms
    
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
        Sheets("WORKINGS").Range("B2:P2").Copy
        
        .Range("B2:P2").Resize(LR, LC).PasteSpecial Paste:=xlPasteFormats
    
    End With
    
    End Sub

    And this works on the sample provided


    Sub format_inte_pastespecialformatnew()
    
    Dim LR As Long, LC As Long, ms As Worksheet
    
    Set ms = Sheets("EXPECTED RESULTS ")
    
    With ms
    
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
        Sheets("Consolidated").Range("B2:P2").Copy
        
        .Range("B2:P2").Resize(LR, LC).PasteSpecial Paste:=xlPasteFormats
        
        End With
    
    End Sub

  10. #10
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    AB33

    nearly on the right track, just at columns Q and row 8 shows a discrepancy on actual macro .
    On the expected sheets results there are formula in the columns yellow and green cells , some format cells green and yellow has non contigious cells formulas .
    my apology for this insight
    Attached Files Attached Files

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: assistance on paste special formats vba code

    JEAN1972

    Are you trying to confuse us....Your new workbook depicts something totally different from original request...
    If you want to copy over the formats as well as per file then record a macro and get result needed...i.e.
    PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
    Last edited by Sintek; 05-04-2017 at 01:28 PM.

  12. #12
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    Sintek

    no,The file itself is big spreadsheet, what I was trying to explain instead of column (H2:V2).I condensed a sample starting from columns A with data instead of G
    and the range paste special format is the same just columns have changed , otherwise if the correct coding was working, would change the range

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: assistance on paste special formats vba code

    I see, the surely AB33 solves your problem in Post 10

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    Hi Jean,
    The code only copies Range("B2:P2"). If you want to expand.

    Range("B2:Q2").
    Try this one

    Sub format_inte_pastespecialformat()
    
    Dim LR As Long, LC As Long, ms As Worksheet
    
    Set ms = Sheets("consolidation DATA")
    
    With ms
    
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        LC = .Cells(1, .Columns.Count).End(xlToLeft).Column
        Sheets("WORKINGS").Range("B2:Q2").Copy
        
        .Range("B2").Resize(LR, LC).PasteSpecial Paste:=xlPasteFormats
    
    End With
    
    End Sub

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    Okay, I see it is colouring row 8 as well, please change this line

    LR = .Range("A" & .Rows.Count).End(xlUp).Row

    INTO

    LR = .Range("A" & .Rows.Count).End(xlUp).Row - 1

  16. #16
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,142

    Re: assistance on paste special formats vba code

    Hi AB33

    Thank you now we are on the right track , it is working, but I am confused as below

    the column Q remains with no colour format green


    
    Sheets("WORKINGS").Range("B2:Q2").Copy
    but with P2 it format column Q green as the physical range (B2:P2)?

    
    Sheets("WORKINGS").Range("B2:P2").Copy
    Can you advise so if I want range (B2:F2) physical range , I need to put (B2 :G2)
    Last edited by JEAN1972; 05-04-2017 at 02:46 PM.

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance on paste special formats vba code

    Hi Jean,
    It was my mistake.
    What is important is the copy range.

    Sheets("WORKINGS").Range("B2:P2").Copy

    means columns B: P and when you paste it, you only need the starting range, not the whole range.
    It does not format Column Q as there is no format in column Q. If you look at the data, the range stretches to column P, not Q, but if your format column Q and paste it, you will see the result.
    B- P- there are 15 columns, so when you paste it, it paste it on 15 columns.

+ 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. How can I get my formula to 'paste special values' to preserve date formats?
    By mltornroth in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-08-2013, 12:37 AM
  2. Loop with Paste Special Values, Formats but no Borders
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2012, 10:07 AM
  3. [SOLVED] Copy and paste special values and formats
    By Blake 7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2012, 07:14 AM
  4. [SOLVED] paste special with widths & formats
    By KAPearson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2012, 07:17 AM
  5. Paste Special Values and Formats
    By robertc12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2009, 02:22 PM
  6. Paste Special: Values, Formats, and Comments
    By nhrav in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2008, 03:33 AM
  7. Paste Special Formats Generated by Conditional Formatting
    By ExcelMonkey in forum Excel General
    Replies: 6
    Last Post: 05-22-2006, 02:10 PM
  8. [SOLVED] keyboard shortcuts for paste-special/formats/value/...
    By xirx in forum Excel General
    Replies: 1
    Last Post: 04-21-2005, 09:07 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