+ Reply to Thread
Results 1 to 4 of 4

inserting rows from different sheets into master sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: inserting rows from different sheets into master sheet

    I've managed some issues and my code now is:

    Sub pruebas2_funciona()
    '
    ' Macro4 Macro
    ' Macro recorded 11-01-2011 by amoya
    
    Dim direccion1 As Integer
    Dim direccion2 As Integer
    Dim dir As Integer
    Dim hoja As Worksheet
    Dim libro As Workbook
    Dim contador As Integer
    Dim i As Integer
    Dim dirn As Integer
    Dim rango As Range
    
    
    
    Set libro = ActiveWorkbook
    contador = ActiveWorkbook.Worksheets.Count
    
    For i = 2 To contador - 2
    
        Cells.Find(What:="Nave", LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        Cells.FindNext(After:=ActiveCell).Activate
        direccion1 = ActiveCell.Row
        
        Cells.Find(What:="Total Consumo", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            
        direccion2 = ActiveCell.Row
        dir = direccion2 - direccion1
        dirn = dir + 9
    
        Range("B" & direccion1, "M" & direccion2).Select
        Selection.Copy
        
        Sheets("EA").Select
        
        Range("E8", "P" & dirn).Select
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
            
        
        Rows("8:" & dirn).Select
        Application.CutCopyMode = False
        Selection.Insert Shift:=xlDown
        
    Next i
    
    End Sub
    But I can't call the macro from the master sheet How do I fix that?
    When I call the macro from the other sheets, It "kinda" works.. I have some issues with the ranges, so the data appears weird.

    Is there a way to store "selection.copy"?

    Thank you

  2. #2
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: inserting rows from different sheets into master sheet

    I'm still having problems and this should be really simple!

    Sub pruebas2_funciona()
    '
    ' Macro4 Macro
    ' Macro recorded 11-01-2011 by amoya
    
    Dim direccion1 As Integer
    Dim direccion2 As Integer
    Dim dir As Integer
    Dim hoja As Worksheet
    Dim libro As Workbook
    Dim contador As Integer
    Dim i As Integer
    Dim dirn As Integer
    Dim rn As Range
    
    
    Set libro = ActiveWorkbook
    contador = ActiveWorkbook.Worksheets.Count
    
    For Each hoja In libro.Worksheets
        If hoja.Name <> "EA" Or hoja.Name <> "NG" Or hoja.Name <> "Listas" Then
    
            
            Cells.Find(What:="Nave", After:=hoja.Range("A1"), LookIn:=xlFormulas, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            True, SearchFormat:=False).Activate
            direccion1 = ActiveCell.Row
            
            Cells.Find(What:="Total Consumo", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
                :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Activate
                
            direccion2 = ActiveCell.Row
            dir = direccion2 - direccion1
            dirn = dir + 9
        
            Range("B" & direccion1, "M" & direccion2).Select
            Selection.Copy
            
            Sheets("EA").Select
            
          
            Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
                xlNone, SkipBlanks:=False, Transpose:=False
                
            Rows(8 & ":" & dirn).Select
            Application.CutCopyMode = False
            Selection.Insert Shift:=xlDown
            
    
    
        End If
    Next hoja
    
    End Sub
    It seems that the macro doesn't run over all the sheets, how can I fix this?

  3. #3
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: inserting rows from different sheets into master sheet

    The code finally works Even if I nobody answered, I read the other topics and they were VERY helpful. Thank you

    Sub actualizar()
    '
    ' Macro4 Macro
    ' Macro recorded 11-01-2011 by amoya
    
    Dim direccion1 As Integer
    Dim direccion2 As Integer
    Dim dir As Integer
    Dim hoja As Worksheet
    Dim libro As Workbook
    Dim contador As Integer
    Dim i As Integer
    Dim j As Integer
    
    
    Set libro = ActiveWorkbook
    contador = ActiveWorkbook.Worksheets.Count
    
    
    For i = 2 To contador - 2
    
        Sheets(i).Select
        Cells.Find(What:="Nave", LookIn:=xlFormulas, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            True, SearchFormat:=False).Activate
    
        direccion1 = ActiveCell.Row
        
        Cells.Find(What:="Total Consumo", LookIn:=xlFormulas, After:=ActiveCell, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            
        direccion2 = ActiveCell.Row
        dir = direccion2 - direccion1
    
        Range("B" & direccion1, "M" & direccion2).Select
        Selection.Copy
        Sheets("EA").Select
        dirn = dir + 10
        
    
    
        
        Range("E8", "P" & dirn).Select
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
                xlNone, SkipBlanks:=False, Transpose:=False
    
        If i <> contador - 2 Then
            Rows(8 & ":" & dirn).Select
            Selection.Insert Shift:=xlDown
        End If

+ 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.6.0 RC 1