2016-11-29 4 views
0

Ich habe viele Fragen über das Auffinden von Lücken in Spaltendaten gesehen, konnte aber die Antworten nicht umsetzen, um meine Anforderungen zu erfüllen. Ich bin ein Amateur so weit wie VBA betroffen ist, nur um mein Leben herausfordernd zu machen!Suche nach Lücken in den Spaltendaten

Ich habe eine Spalte mit Zahlen in einer Excel-Datei. Die Spalte enthält einzelne und mehrere aufeinanderfolgende leere Zellen. Ich muss die leeren Stellen lokalisieren und die Excel-Funktion verwenden, um die Lücken mit Daten mit linearer Reihenfüllfunktion zu füllen. Vielen Dank im Voraus für jede Anleitung.

bisher Mein Code ist

Dim lngLastRow As Long 

lngLastRow = Cells(Rows.Count, "F").End(xlUp).Row 'Search Column F, change as required.  

For Each cell In Range("F3:F" & lngLastRow) 'Starting cell is F3  
    If IsEmpty(Range("F3").Value) = True Then 

    'store this row and check is next cell is blank & apply fill process  

    End If 
Next cell 
+0

Wenn Sie nur die Informationen aus der Zelle über Änderung Ihrer 'If' Block wollen greifen .... 'If IsEmpty (Zelle) Dann cell.value = cell.offset (-1) .Value ... braucht in diesem Fall kein' End If'. –

Antwort

1

Hoffentlich dieser Code eine lineare Füllung erreichen:

Sub LinearFill() 
    Dim lngLastRow As Long 
    Dim endRow As Long 
    Dim startValue As Double 
    Dim endValue As Double 
    Dim thisRow As Long 

    With ActiveSheet 
     lngLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row 'Search Column F, change as required. 
     For thisRow = 3 to lngLastRow - 1 
      If IsEmpty(.Cells(thisRow, "F")) Then 
       startValue = CDbl(.Cells(thisRow - 1, "F").Value) 
       endRow = .Cells(thisRow, "F").End(xlDown).Row 
       endValue = CDbl(.Cells(endRow, "F").Value) 
       .Cells(thisRow, "F").Value = startValue + (endValue - startValue)/(endRow - thisRow + 1) 
      End If 
     Next 
    End With 
End Sub 
+0

Vielen Dank. Nur die Arbeit! – GeoffB

Verwandte Themen