예상 독서 시간: 3 세부 사항
다음 Sub 프로시저는 빈 셀이 나타날 때까지 활성 워크시트의 A열에 있는 셀에서 값을 읽습니다. 값은 배열에 저장됩니다. 이 간단한 Excel 매크로 예제는 다음의 사용을 보여줍니다.
Do Until
;Ubound
내장(배열의 가장 높은 인덱스를 반환).' Sub procedure store values in Column A of the active Worksheet
' into an array
Sub GetCellValues()
Dim iRow As Integer ' stores the current row number
Dim dCellValues() As Double ' array to store the cell values
iRow = 1
ReDim dCellValues(1 To 10)
' Do Until loop to extract the value of each cell in column A
' of the active Worksheet, as long as the cell is not blank
Do Until IsEmpty(Cells(iRow, 1))
' Check that the dCellValues array is big enough
' If not, use ReDim to increase the size of the array by 10
If UBound(dCellValues) < iRow Then
ReDim Preserve dCellValues(1 To iRow + 9)
End If
' Store the current cell in the CellValues array
dCellValues(iRow) = Cells(iRow, 1).Value
iRow = iRow + 1
Loop
End Sub
이 프로시저는 활성 워크시트의 A열에 있는 값을 배열에 저장합니다. 다음 사항에 유의하세요.
Do Until
빈 셀을 무시하고 활성 워크시트의 A열에 있는 각 셀의 값을 추출합니다.If UBound(dCellValues) < iRow
” dCellValues 배열이 정보를 담을 수 있을 만큼 충분히 큰지 확인하고, 그렇지 않은 경우 ReDim을 사용하여 배열 크기를 10만큼 늘립니다.dCellValues(iRow) = Cells(iRow, 1).Value
" 현재 셀을 CellValues 배열에 저장합니다.다음 Sub 프로시저는 "Sheet2"라는 워크시트의 A열에서 값을 읽고 해당 값에 대해 산술 연산을 수행합니다. 결과 값은 현재 활성 워크시트의 A열에 인쇄됩니다.
이 매크로는 다음을 보여줍니다.
Do Until
;' Sub procedure to loop through the values in Column A of the Worksheet
' "Sheet2", perform arithmetic operations on each value, and write the
' result into Column A of the current Active Worksheet ("Sheet1")
Sub Transfer_ColA()
Dim i As Integer
Dim Col As Range
Dim dVal As Double
' Set the variable 'Col' to be Column A of Sheet 2
Set Col = Sheets("Sheet2").Columns("A")
i = 1
' Loop through each cell of the column 'Col' until
' a blank cell is encountered
Do Until IsEmpty(Col.Cells(i))
' Apply arithmetic operations to the value of the current cell
dVal = Col.Cells(i).Value * 2 + 1
' The command below copies the result into Column A
' of the current Active Worksheet - no need to specify
' the Worksheet name as it is the active Worksheet.
Cells(i, 1) = dVal
i = i + 1
Loop
End Sub
시트의 특정 범위에 있는 셀이 업데이트될 때 실행되는 간단한 VBA 매크로를 작성해 보겠습니다. B열(B4~B11)의 변경 사항을 추적하고 A열에 변경 날짜와 시간을 기록한다고 가정해 보겠습니다.
다음과 같이 진행해보자:
Developer
옵션 "을 클릭하세요.Visual Basic
”을 클릭하여 VBA 편집기를 엽니다. Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B1:B10")) Is Nothing Then
Target.Range("A1:A1").Value = Now
End If
End Sub
매크로가 활성화된 통합 문서를 저장합니다(예: .xlsm 파일).
이제 B열의 셀(1행에서 10행까지)을 업데이트할 때마다 A열의 셀에 현재 날짜와 시간이 자동으로 표시됩니다.
Ercole Palmeri
Coveware by Veeam은 계속해서 사이버 강탈 사건 대응 서비스를 제공할 것입니다. Coveware는 법의학 및 교정 기능을 제공할 것입니다…
예측 유지보수는 플랜트 관리에 대한 혁신적이고 적극적인 접근 방식을 통해 석유 및 가스 부문에 혁명을 일으키고 있습니다.…
영국 CMA는 인공 지능 시장에서 Big Tech의 행동에 대해 경고를 발표했습니다. 거기…
건물의 에너지 효율성을 높이기 위해 유럽 연합이 제정한 "Case Green" 법령은 다음과 같이 입법 과정을 마무리했습니다.