Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Andrea,
Grazie di nuovo Norman, molto utile vedere come cambia il codice.
La cella B10 viene copiata in ogni riga nella colonna B e non nella colonna E ma va bene lo stesso. Posso copiare il valore tutto in maiuscolo?
Prova:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim srcWB As Workbook, destWB As Workbook
Dim SH As Worksheet, destSH As Worksheet
Dim rDati As Range, rHeaders As Range, rDest As Range
Dim iRow As Long, jRow As Long
Dim CalcMode As Long
Dim bHeader As Boolean
Const sFile As String = _
"20180703_Esempio_Consolida.xlsx" '<<=== Modifica
Const sFoglioDaEscludere As String = "Indice" '<<=== Modifica
Const sColonne As String = "A:AV" '<<=== Modifica
On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Set srcWB = Workbooks.Open(sFile)
Set destWB = ThisWorkbook
Set destSH = destWB.Sheets(1)
For Each SH In srcWB.Worksheets
With SH
If .Name <> sFoglioDaEscludere Then
If Not bHeader Then
Set rHeaders = Intersect(.Rows("10:12"), .Columns(sColonne))
rHeaders.Copy
With destSH.Range("A10")
.PasteSpecial (xlPasteAll)
.PasteSpecial (xlPasteColumnWidths)
End With
bHeader = True
End If
iRow = LastRow(SH, .Columns(sColonne), 13)
With destSH
jRow = LastRow(destSH, .Columns(sColonne), 12)
Set rDest = .Range("A" & jRow + 1)
End With
Set rDati = Intersect(.Rows("13:" & iRow), .Columns(sColonne))
rDati.Copy Destination:=rDest
rDest.Resize(rDati.Rows.Count).Value = UCase(.Name**)**
End If
End With
Next SH
With destSH
.Columns(1).Copy
.Columns(5).Insert Shift:=xlToRight
.Columns(5).AutoFit
.Columns(1).ClearContents
End With
srcWB.Close SaveChanges:=False
Call MsgBox( _
Prompt:="Finito", _
Buttons:=vbInformation, _
Title:="REPORT")
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
End Function
'<<=========
===
Regards,
Norman