Skoči na vsebino

IPB




Slika

Excel Vba


1 odgovor na temo

#1 matija

matija

    nOObie

  • Members
  • 24 objav

Objavljeno 30 avgust 2018 - 10:11

Želim narediti makro, ki mi bo vsebino tabel iz večih dokumentov kopiral v novo skupno tabelo. 

Na internetu sem našel makro, ki to zelo lepo naredi, edini problem je da povozi podatke. Če znam kdo pomagat kako prirediti makro, da se podatki ne bodo povozili. Torej če sto v večih tabelah na istih mestih podatki se le ti povozijo s podatki iz nazadnje kopiranim dokumentom. 

 

Sub ximpleXlsMerger2()
Dim wb As Workbook, sh As Worksheet, fPath As String, fName As String
Set sh = ThisWorkbook.Sheets(1)
fPath = ThisWorkbook.Path 'If files are in a different directory than master, replace path here
    If Right(fPath, 1) <> "\" Then fPath = fPath & "\" 'Make sure separator is on end of path
fName = Dir(fPath & "*.xl*") 'get all Excel files in directory
    Do
        If fName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(fPath & fName)
            With wb.Sheets(1)
                If Application.CountA(.Rows(2)) > 0 Then
                    .UsedRange.Offset(1).Copy sh.Cells(Rows.Count, 1).End(xlUp)(2)
                End If
            End With
            wb.Close False
        End If
        fName = Dir
    Loop While fName <> ""
End Sub


#2 zgubar

zgubar

    nOObie

  • Members
  • 3 objav

Objavljeno 03 september 2018 - 13:49

Namesto

 

.UsedRange.Offset(1).Copy sh.Cells(Rows.Count, 1).End(xlUp) (2)

 

napiši

 

.UsedRange.Copy sh.Cells(sh.Cells(sh.Rows.Count, 1).End(xlUp).Row + 1, 1)





Dodaj odgovor



  


0 član(ov) bere to temo

0 članov, 0 gostov, 0 anonimnih uporabnikov