Sub AutoFill()
Dim x As Long
Dim y As Long
Dim lastrow As Long
Dim lastcolumn As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
lastcolumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
lastrow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
For x = 2 To lastrow
If Cells(x, 2).Value = "" Then
Cells(x, 2).Value = Cells(x - 1, 2).Value
Cells(x, 3).Value = Cells(x - 1, 3).Value
Cells(x, 5).Value = Cells(x - 1, 5).Value
End If
Next x
Application.ScreenUpdating = True
End Sub
위의 코드를 사용하면 셀이 채워지지만 마지막 행이 Excel 시트 끝까지 채워집니다. 엑셀 시트 란에 C
E
이 이미 채워져있는 D
은 자동으로 아래로 채워야합니다. 코드의 변경 사항은 무엇입니까?Excel에서 셀 자동 채우기 VBA 매크로
왜'ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count' ?? HTTP : //stackoverflow.com/questions/71180/how-can-i-find-last-row- 그 - 포함 - 엑셀 - 시트 -와 - 매크로 – cyboashu
귀하의 코드는 내 PC에 귀하의 요구 사항에 따라 노력하고 있습니다. [확인] (https://www.dropbox.com/s/kg380esjoyxb0o9/autofill_sample.xlsm?dl=0) – skkakkar
lastRow의 경우 3 열을 비교하고 거기에서 마지막 행을 가져옵니다. 'UsedRange'는 제 경험상 항상 기대했던 범위를 사용하지는 않습니다. lastRow = 셀 (rows.count, 2) .End (xlUp) .Row, cells (rows.count, 3) .End (xlUp) .Row, cells (rows.count, 5) .End (xlUp) .Row' * 또는 * LastRow = Cells.Find ("*", searchorder : = xlByRows, searchdirection : = xlPrevious) .Row' – BruceWayne