Tempu di lettura stimatu: 3 minuti
A seguente prucedura Sub leghje i valori da e cellule in a colonna A di u fogliu di travagliu attivu, finu à ch'ellu scontra una cellula bianca. I valori sò almacenati in un array. Stu sèmplice esempiu macro Excel illustra l'usu di:
Do Until
;Ubound
builtin (chì torna l'indice più altu di un 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
A prucedura guarda i valori in a colonna A di u fogliu di travagliu attivu in un array, nota chì:
Do Until
estrae i valori di ogni cellula in a colonna A di u fogliu di travagliu attivu, ignorendu e cellule in biancuIf UBound(dCellValues) < iRow
" verifica chì a matrice dCellValues hè abbastanza grande per mantene l'infurmazioni, se no, utilizate ReDim per aumentà a dimensione di l'array di 10.dCellValues(iRow) = Cells(iRow, 1).Value
” Memorizza a cellula attuale in a matrice CellValuesA seguita sottu prucedura leghje i valori da a colonna A di u fogliu di travagliu chjamatu "Sheet2" è eseguisce operazioni aritmetiche nantu à i valori. I valori risultanti sò stampati in a colonna A di u fogliu di travagliu attivu attuale.
Questa macro illustra:
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
Scrivemu una macro VBA simplice chì spara quandu una cellula in un intervallu specificu di a nostra foglia hè aghjurnata. Suppone chì vulete seguità i cambiamenti in a colonna B (B4 à B11) è registrà a data è l'ora di u cambiamentu in a colonna A.
Procedemu cusì:
Developer
cliccate nantu à l'opzione "Visual Basic
"per apre l'editore 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
Salvà u libru di travagliu cù macros attivati (per esempiu, cum'è un schedariu .xlsm).
Avà, ogni volta chì aghjurnà una cellula in a colonna B (da a fila 1 à a fila 10), a cellula in a colonna A mostrarà automaticamente a data è l'ora attuale.
Ercole Palmeri
Coveware da Veeam continuerà à furnisce servizii di risposta à l'incidentu di l'estorsione cibernetica. Coveware offre capacità forensiche è di rimediazione ...
U mantenimentu predittivu rivoluziona u settore di petroliu è gasu, cù un approcciu innovativu è proattivu à a gestione di e piante.
A CMA di u Regnu Unitu hà emessu un avvisu annantu à u cumpurtamentu di Big Tech in u mercatu di l'intelligenza artificiale. Ci…
U decretu "Green Houses", formulatu da l'Unione Europea per rinfurzà l'efficienza energetica di l'edificazioni, hà cunclusu u so prucessu legislativu cù ...