Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Pierluigi,
devo estrarre da un elenco posizionato in BA5:BP200 solo le righe che hanno il font di colore rosso e copiarle in CA5:CP5
Si può ottenere con un codice VBA ?
Il carattere delle righe è il classico font rosso e non è ottenuto con la formattazione condizionale.
Ho visto che la versione excel minimale dovrebbe essere 2007 va bene ugualmente perchè poi in excel 2003 attiverei la compatibilità
Peiva qualcosa del genere:
- Alt+F11 per aprire l'editor di VBA
- Alt+IMper inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim srcRng As Range, destRng As Range
Dim copyRng As Range, rCell As Range
Dim iRow As Long, iCols As Long, LRow As Long
Dim CalcMode As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Const sElenco As String = "BA5:BP200"
Const sDestinazione As String = " CA5"
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
Set srcRng = .Range(sElenco)
Set destRng = .Range(sDestinazione)
End With
With srcRng
iRow = srcRng.Row
iCols = .Columns.Count
End With
LRow = LastRow(SH, srcRng)
Set srcRng = srcRng.Resize(LRow - iRow + 1)
For Each rCell In srcRng.Columns(1).Cells
With rCell
If Application.CountA(.Resize(1, iCols)) Then
If .Font.Color = vbRed Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
End If
End With
Next rCell
If Not copyRng Is Nothing Then
On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Intersect(copyRng.EntireRow, srcRng).Copy Destination:=destRng
Else
'\ Nulla da copiare! Fai niente
End If
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
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
End Function
'<<=========
- Alt+Q per chiudere l'editor di VBA e tornare a Excel
- Salva il file con l’estensione xlsm
- Alt+F8 per aprire la finestra di gestione delle macro
- Seleziona Tester | Esegui
Questo codice dovrebbe funzionare altrettanto bene sia con Excel 2003 che una versione successiva.
Potresti scaricare il mio file di prova Pierluigi20170421.xlsm a:
https://www.dropbox.com/s/ld2mri79tua891o/Perliugi20170421.xlsm?dl=0
===
Regards,
Norman