Due giorni fa avevo proposto un problema in Excel (e ho avuto risposta da uno dei due guru che, oltretutto, non credevo mi leggesse 🙂 ).
Bene, ecco la mia soluzione:
1. Situazione iniziale:
ID | VALORE1 | VALORE2 | VALORE3 | VALORE4 |
1 | ||||
A | B | C | D | |
E | F | G | H | |
I | L | M | N | |
2 | ||||
A | B | C | D | |
E | F | G | H | |
I | L | M | N |
2. Abbassare di una riga la prima colonna, di modo da ottenere una soluzione di questo tipo:
ID | VALORE1 | VALORE2 | VALORE3 | VALORE4 |
1 | A | B | C | D |
E | F | G | H | |
I | L | M | N | |
2 | A | B | C | D |
E | F | G | H | |
I | L | M | N |
3. Applicare questa macro di modo da eliminare tutte le righe vuote del Foglio sul quale stiamo lavorando:
Sub DEL95HTMLemptyCells()
Application.ScreenUpdating = False
Application.Calculation = xlManual ‘–Excel 95
Dim Rcnt As Long, Ccnt As Long, r As Long, c As Long
Dim CurrCell As Range
On Error Resume Next
Selection.Replace What:=Chr(160), Replacement:=Chr(32), _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=True
Rcnt = Cells.SpecialCells(xlLastCell).Row
Ccnt = Cells.SpecialCells(xlLastCell).Column
For r = Rcnt To 2 Step -1
If IsEmpty(Cells(Rcnt, 1)) Then
For c = 1 To Ccnt
If Not IsEmpty(Cells(r, c)) Then
If Not IsEmpty(Cells(r – 1, c)) Then GoTo notthis
End If
Next c
For c = 1 To Ccnt
If Not IsEmpty(Cells(r, c)) Then
Cells(r – 1, c) = Cells(r, c)
End If
Next c
Cells(r, 1).EntireRow.Delete
notthis:
End If
Next r
Application.Calculation = xlAutomatic ‘–Excel 95
Application.ScreenUpdating = True
End Sub(via mvps.org)
4. Una volta eliminate tutte le righe vuote, selezioniamo tutta la prima colonna, f5, seleziona speciali, seleziona “Celle Vuote”. A questo punto, imponiamo una formula che valorizzi la prima cella vuota selezionata con il valore della prima cella valorizzata .. et voilà, avremo lo schema richiesto