Consulting

Results 1 to 5 of 5

Thread: Using Copy Destination for values and number formatting

  1. #1
    VBAX Regular
    Joined
    Oct 2013
    Location
    Zurich
    Posts
    14
    Location

    Using Copy Destination for values and number formatting

    Hey guys,

    I have the below code which copies the row B from each worksheet into my Master Data sheet. How can I adjust it so that it pastes only the values and number formatting?

    [VBA]
    Sub CopyRows2ToDataSheet()

    Dim ws As Worksheet, _
    LR As Long
    Application.ScreenUpdating = False

    For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Master Data sheet" Then

    LR = Sheets("Master Data sheet").Range("A" & Rows.Count).End(xlUp).Row + 1
    ws.Range("2:2").Copy Destination:=Sheets("Master Data sheet").Range("A" & LR1)
    End If

    Next ws
    Application.ScreenUpdating = True
    End Sub
    [/VBA]


    Thanks a lot, Viktor

  2. #2
    Record the action in excel pasting as values and formatting as numbers.

  3. #3
                LR = Sheets("Master Data sheet").Range("A" & Rows.Count).End(xlUp).Row + 1 
                ws.Range("2:2").Copy Destination:=Sheets("Master Data sheet").Range("A" & LR1), Paste:=xlPasteValues
                Sheets("Master Data sheet").Range("A" & LR1).NumberFormat:= "0.00"

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You can't do that using destination
    [vba]ws.Range("2:2").Copy
    Sheets("Master Data sheet").Range("A" & LR1).PasteSpecial xlPasteValuesAndNumberFormats
    [/vba]
    Be as you wish to seem

  5. #5
    VBAX Regular
    Joined
    Oct 2013
    Location
    Zurich
    Posts
    14
    Location
    Quote Originally Posted by Aflatoon View Post
    You can't do that using destination
    [vba]ws.Range("2:2").Copy
    Sheets("Master Data sheet").Range("A" & LR1).PasteSpecial xlPasteValuesAndNumberFormats
    [/vba]
    This one worked great!
    The issue with the other approach was that different columns of the rows I was copying had different formatting, so I couldn't just apply single format style for all of them.

    Thank you both,
    Viktor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •