2017-01-10 17 views
1

間の空のセルの状況を記入:細胞上
「A1」私は価値細胞上の細胞について「1」
「A10」私は値を持っている「2」
「A20を有しますA30 3 『セル上で
『"私は値を持っている』』私は価値を持っている『4』2つの充填されたセル

私はエクセルVBAでやりたい:A1とA10の間
が空のセルがあります。私はA2:A9がA10の値で満たされていることを意味します、それは "2"を意味します。
A10とA20の間に空のセルがあります。 A11:19がA20の値で満たされていれば、それは「3」を意味します。

問題はA1からA30の範囲が固定されていないことです。私は、空ではないセルについては行全体を検索し、それらの間のセルを塗りつぶした上のセルに塗りつぶしたいと思います。

編集:
さらに説明すると、Accessデータベースには、日付で満たされたテーブルと数字でいっぱいのテーブルがあります。

Excelシートにレポートを作成したいと考えています。

Dim Daten As Variant 
Daten = Array(rs!DatumJMinus8Monate, rs!DatumJ, rs!DatumI, rs!DatumH, rs!DatumG, rs!DatumF, rs!DatumE, rs!DatumD, rs!DatumC, rs!DatumB, rs!DatumA, rs!DatumA4Monate) 
Dim Bedarfe As Variant 
Bedarfe = Array(rs!BedarfJ8Monate, rs!BedarfJ, rs!BedarfI, rs!BedarfH, rs!BedarfG, rs!BedarfF, rs!Bedarfe, rs!BedarfD, rs!BedarfC, rs!BedarfB, rs!BedarfA, rs!BedarfA, "") 

Dim neuereintrag As Boolean 
bedarfindex = 0 
For Each element In Daten 
    i = 7 
    For jahre = 1 To 10 
     If Cells(1, i + 1) = Year(element) Then 
      For monate = 1 To 12 
       If Cells(2, i + monate) = Month(element) Then 
        Cells(zeile, i + monate) = Bedarfe(bedarfindex) 
        Cells(zeile, i + monate).Font.Bold = True 
        bedarfindex = bedarfindex + 1 
        neuereintrag = True 
       ElseIf IsEmpty(Cells(zeile, i + monate)) Or neuereintrag = True Then 
        Cells(zeile, i + monate) = Bedarfe(bedarfindex) 
        neuereintrag = False 
       End If 
      Next monate 
     End If 
     i = i + 12 
    Next jahre 
Next element 

図では、赤い円の数字を削除する必要があります。

下から上へ仕事に向かう途中で

Excel-Report-Sheet Screenshot

+0

あなたは多くの方法を試したと言いましたが、あなたがしたことのいくつかを表示できますか?これは「私のためのコード」サイトではありませんが、私たちが何かを始めてくれたら、あなたの目標に達するのを手伝ってくれます! – PartyHatPanda

+0

あなたの質問を編集し、そこに 'code'を追加してください。 – ManishChristian

+0

私は数分でそれを行います。少し時間が必要です – oemerkk

答えて

0

:このような

Sub FillUp() 
    Dim N As Long 
    Dim i As Long 
    N = Cells(Rows.Count, "A").End(xlUp).Row 
    For i = N - 1 To 1 Step -1 
     If Cells(i, 1).Value = "" Then Cells(i, 1).Value = Cells(i + 1, 1).Value 
    Next i 
End Sub 
+0

ねえ、それは本当に素晴らしいです!ありがとうございました! 唯一のものは、私は説明を間違えています。 私はA1、H1、O1の間のセルを埋めることを望みました。 列ではなく行です。 私はあなたのコードを変更しようとしますが、行と一緒にも動作することを私が変更しなければならないと私に言うことができれば、あなたにも感謝しますか? – oemerkk

+1

ありがとう、男!やったよ!あなたは私のヒーローです! - 1~1 'サブFillUp() 暗いN限り 暗いI限り N =セル(1、Columns.Count).END(xlToLeft).Column についてI = N: これはコードでありますステップ-1 セル(1、i).Value = "" Thenセル(1、i).Value =セル(1、i + 1).Value 次へi End Sub' – oemerkk

+0

@oemerkk Good Job !! –

0

たぶん何か。 2つの値が互いに隣り合っている場合、または列1に値が含まれていない場合は失敗するため、少しの作業が必要です。

Sub AutoFill() 

    Dim rCell1 As Range, rCell2 As Range 

    With ThisWorkbook.Worksheets("Sheet1") 
     'Find the last column containing data, set both references to this 
     'so the Do While doesn't fall over on the first loop. 
     Set rCell2 = .Cells(1, .Columns.Count).End(xlToLeft) '1 is the row number it's looking at. 
     Set rCell1 = rCell2 

     'Find next cell to the left containing data and fill between these two columns. 
     Do While rCell1.Column <> 1 
      Set rCell1 = rCell2.End(xlToLeft) 
      .Range(rCell1, rCell2.Offset(, -1)).FillRight 
      Set rCell2 = rCell1 
     Loop 
    End With 

End Sub