Perkiraan wektu maca: 3 menit
Prosedur Sub ngisor iki maca nilai saka sel ing kolom A saka lembar kerja sing aktif, nganti nemoni sel kosong. Nilai kasebut disimpen ing larik. Conto makro Excel sing prasaja iki nggambarake panggunaan:
Do Until
;Ubound
builtin (sing ngasilake indeks paling dhuwur saka array).' 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
Prosedur nyimpen nilai ing kolom A saka lembar kerja aktif ing larik, cathet yen:
Do Until
ngekstrak nilai saben sel ing kolom A saka lembar kerja aktif, ora nggatekake sel kosongIf UBound(dCellValues) < iRow
" Priksa manawa array dCellValues cukup gedhe kanggo nahan informasi kasebut, yen ora, gunakake ReDim kanggo nambah ukuran array kanthi 10dCellValues(iRow) = Cells(iRow, 1).Value
” Nyimpen sel saiki ing array CellValuesSub prosedur ing ngisor iki maca nilai saka kolom A saka lembar kerja sing jenenge "Sheet2" lan nindakake operasi aritmetika ing nilai kasebut. Nilai asil dicithak ing kolom A saka lembar kerja aktif saiki.
Makro iki nggambarake:
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
Ayo nulis makro VBA prasaja sing murub nalika sel ing sawetara tartamtu saka sheet kita dianyari. Upamane sampeyan pengin nglacak owah-owahan ing kolom B (B4 nganti B11) lan ngrekam tanggal lan wektu owah-owahan ing kolom A.
Ayo nerusake kaya iki:
Developer
klik pilihan"Visual Basic
"kanggo mbukak editor 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
Simpen buku kerja kanthi makro aktif (contone, minangka file .xlsm).
Saiki, saben kita nganyari sel ing kolom B (saka baris 1 nganti baris 10), sel ing kolom A bakal kanthi otomatis nampilake tanggal lan wektu saiki.
Ercole Palmeri
Coveware dening Veeam bakal terus nyedhiyakake layanan respon insiden pemerasan cyber. Coveware bakal nawakake kemampuan forensik lan remediasi…
Pangopènan prediktif ngrevolusi sektor minyak & gas, kanthi pendekatan inovatif lan proaktif kanggo manajemen pabrik.…
CMA UK wis ngetokake bebaya babagan prilaku Big Tech ing pasar intelijen buatan. Ana…
Keputusan "Case Green", sing dirumusake dening Uni Eropa kanggo ningkatake efisiensi energi bangunan, wis rampung proses legislatif kanthi…