Consulting

Results 1 to 5 of 5

Thread: Solved: Merge data as value without formatting

  1. #1

    Solved: Merge data as value without formatting

    Hi pals,

    Could some one help me with my code. I want data from other sheets to be merge in master sheet as value only without formating. The code below return data to master sheet along with formating.

    Code:
    PHP Code:
    Sub AllDataToForthSheet()
        
    Dim SheetCtr As Double
        Dim Last1Row 
    As Double
        Dim LastShtRow 
    As Double
        
    For SheetCtr 5 To ActiveWorkbook.Sheets.Count
            LastShtRow 
    Worksheets(SheetCtr).Cells(Rows.Count"D").End(xlUp).Row
            
    If Worksheets(SheetCtr).Cells(Rows.Count"J").End(xlUp).Row LastShtRow Then
                LastShtRow 
    Worksheets(SheetCtr).Cells(Rows.Count"G").End(xlUp).Row
            End 
    If
     
            
    Last1Row Worksheets(4).Cells(Rows.Count"F").End(xlUp).Row
            
    If Worksheets(4).Cells(Rows.Count"G").End(xlUp).Row Last1Row Then
                Last1Row 
    Worksheets(4).Cells(Rows.Count"J").End(xlUp).Row
            End 
    If
     
            
    Worksheets(SheetCtr).Range("D25:S" LastShtRow).Copy _
            Destination
    :=Worksheets(4).Range("F" Last1Row 1)
     
        
    Next SheetCtr
    End Sub 

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    Change these lines:

    [VBA]Worksheets(SheetCtr).Range("D25:S" & LastShtRow).Copy _
    Destination:=Worksheets(4).Range("F" & Last1Row + 1)
    [/VBA]
    to:
    [VBA]
    Worksheets(SheetCtr).Range("D25:S" & LastShtRow).Copy
    Worksheets(4).Range("F" & Last1Row + 1).PasteSpecial xlPasteValues
    'add this line to turn off the 'copy marching ants'
    Application.CutCopyMode = False

    [/VBA]

  3. #3
    hi mbarron,

    I got this error, 1004

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The following works for me:
    Sub AllDataToForthSheet()
    Application.ScreenUpdating = False
    Dim SheetCtr As Double
    Dim Last1Row As Double
    Dim LastShtRow As Double
    With ActiveWorkbook
      For SheetCtr = 5 To .Sheets.Count
        With .Worksheets(SheetCtr)
          LastShtRow = .Cells(Rows.Count, "D").End(xlUp).Row
          If .Cells(Rows.Count, "J").End(xlUp).Row > LastShtRow Then
            LastShtRow = .Cells(Rows.Count, "G").End(xlUp).Row
          End If
        End With
        With .Worksheets(4)
          Last1Row = .Cells(Rows.Count, "F").End(xlUp).Row
          If .Cells(Rows.Count, "G").End(xlUp).Row > Last1Row Then
            Last1Row = .Cells(Rows.Count, "J").End(xlUp).Row
          End If
        End With
        .Worksheets(SheetCtr).Range("D25:S" & LastShtRow).Copy
        .Worksheets(4).Range("F" & Last1Row + 1).PasteSpecial xlPasteValues
      Next SheetCtr
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Thanks a lots Paul and mBarron for your help.
    I should remarks this thread as solved.


Posting Permissions

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