Moderatori: Anthony47, Flash30005
Private Sub Worksheet_Change(ByVal Target As Range)
'
FileIn = "$C$2" '<<< La cella che punta al file
If Target.Address <> FileIn Then Exit Sub
FormIn = "C20" '<<< La cella con la formula da variare
If Range(FileIn) <> "" Then
Range(FormIn).Formula = _
"= 'H:\produzione\scheda preventivo\[" & _
Range(FileIn).Value & ".xls]CARTIGLIO'!C4" <**
End If
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
FileIn = Trim(Left(Sh.Name, 5))
If IsNumeric(FileIn) Then
FormIn = "C20" '<<< La cella con la formula da variare
Range(FormIn).Formula = _
"= 'H:\produzione\scheda preventivo\[" & _
FileIn & ".xls]CARTIGLIO'!C4" '<**
End If
End Sub
Private Sub Worksheet_Activate()
Dim myBase(1 To 4)
myBase(1) = "'H:\produzione\scheda preventivo\[ZCZCX.xls]CARTIGLIO'!A3"
myBase(2) = "'H:\produzione\scheda preventivo\[ZCZCX.xls]CARTIGLIO'!C3"
myBase(3) = "'H:\produzione\scheda preventivo\[ZCZCX.xls]CARTIGLIO'!B3"
myBase(4) = "'H:\produzione\scheda preventivo\[ZCZCX.xls]CARTIGLIO'!D3"
'Check esistenza file:
mySplit = Split(myBase(1), "[")
myFile = Replace(mySplit(0), "'", "") & Range("$D$2").Value & ".xls"
If Len(Dir(myFile)) = 0 Then
MsgBox ("il file " & myFile & " non esiste" & vbCrLf & _
"Le formule non sono state alterate")
Exit Sub
End If
'
Application.EnableEvents = False
LastA = Cells(Rows.Count, 1).End(xlUp).Row
For I = 1 To 4
Cells(3, 1 + I).Resize(LastA - 3, 1).FormulaLocal = "=" & Replace(myBase(I), "ZCZCX", Range("$D$2").Value)
Next I
Application.EnableEvents = True
End Sub
ActiveSheet.Name = Left([D2] & " " & [C2], 31)
Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
Dim myBase(1 To 12)
myBase(1) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!A2"
myBase(2) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!B2"
myBase(3) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!C2"
myBase(4) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!D2"
myBase(5) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!E2"
myBase(6) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!F2"
myBase(7) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!G2"
myBase(8) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!H2"
myBase(9) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!I2"
myBase(10) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!J2"
myBase(11) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!K2"
myBase(12) = "'H:\disegni\commesse\[ZCZCX.xlsm]ORDINI'!L2"
'Check esistenza file:
mySplit = Split(myBase(1), "[")
myFile = Replace(mySplit(0), "'", "") & Range("$b$1").Value & ".xlsm"
If Len(Dir(myFile)) = 0 Then
MsgBox ("il file " & myFile & " non esiste" & vbCrLf & _
"Le formule non sono state alterate")
Exit Sub
End If
'
Application.EnableEvents = False
LastA = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To 12
Cells(2, 0 + i).Resize(LastA - 1, 1).FormulaLocal = "=" & Replace(myBase(i), "ZCZCX", Range("$b$1").Value)
Next i
Application.EnableEvents = True
ActiveSheet.Name = Left([B1] & " " & [C2], 7)
ActiveSheet.Protect
End Sub
La macro parte dal presupposto che il foglio contenga gia' delle formule "statiche", e le modifica per inserire un nome file "dinamico".Tutto ok tranne che mi esegue la ricerca sui file esterni solo fino ad un certo numero di righe.
Non riesco a capire quale funzione nella macro determina per quante righe (dalla seconda in poi)
itero il procedimento (io vorrei impostare da 2 a 2000 ad esempio come è possibile?
[NomeFile.xls]NomeFoglio
myBase(1) = "'H:\produzione\scheda preventivo\ZCZCX'!A3"
myBase(2) = "'H:\produzione\scheda preventivo\ZCZCX'!C3"
'etc
'etc
Torna a Applicazioni Office Windows
Inserire dati filtrati da 2 file ad un terzo file Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 14 |
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
Visitano il forum: Nessuno e 47 ospiti