ពេលវេលាអានប៉ាន់ស្មាន៖ 3 មីទីតូ។
នីតិវិធីរងខាងក្រោមអានតម្លៃពីក្រឡាក្នុងជួរ A នៃសន្លឹកកិច្ចការសកម្ម រហូតដល់វាជួបក្រឡាទទេ។ តម្លៃត្រូវបានរក្សាទុកក្នុងអារេមួយ។ ឧទាហរណ៍ម៉ាក្រូ Excel ដ៏សាមញ្ញនេះបង្ហាញពីការប្រើប្រាស់៖
Do Until
;Ubound
builtin (ដែលត្រឡប់សន្ទស្សន៍ខ្ពស់បំផុតនៃអារេមួយ) ។' 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 ដើម្បីបង្កើនទំហំអារេដោយ 10dCellValues(iRow) = Cells(iRow, 1).Value
រក្សាទុកក្រឡាបច្ចុប្បន្ននៅក្នុងអារេ CellValuesនីតិវិធីរងខាងក្រោមអានតម្លៃពីជួរ A នៃសន្លឹកកិច្ចការដែលមានឈ្មោះថា "សន្លឹក 2" ហើយអនុវត្តប្រតិបត្តិការនព្វន្ធលើតម្លៃ។ តម្លៃលទ្ធផលត្រូវបានបោះពុម្ពក្នុងជួរឈរ 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 ដោយ Veeam នឹងបន្តផ្តល់សេវាកម្មឆ្លើយតបឧប្បត្តិហេតុជំរិតទារប្រាក់តាមអ៊ីនធឺណិត។ Coveware នឹងផ្តល់ជូននូវសមត្ថភាពផ្នែកកោសល្យវិច្ច័យ និងដំណោះស្រាយ…
ការថែទាំតាមទស្សន៍ទាយកំពុងធ្វើបដិវត្តវិស័យប្រេង និងឧស្ម័ន ជាមួយនឹងវិធីសាស្រ្តប្រកបដោយភាពច្នៃប្រឌិត និងសកម្មចំពោះការគ្រប់គ្រងរោងចក្រ។…
CMA របស់ចក្រភពអង់គ្លេសបានចេញការព្រមានអំពីអាកប្បកិរិយារបស់ Big Tech នៅក្នុងទីផ្សារបញ្ញាសិប្បនិម្មិត។ នៅទីនោះ…
ក្រឹត្យ "Case Green" ដែលបង្កើតដោយសហភាពអឺរ៉ុប ដើម្បីបង្កើនប្រសិទ្ធភាពថាមពលនៃអគារ បានបញ្ចប់ដំណើរការនីតិប្បញ្ញត្តិរបស់ខ្លួនជាមួយនឹង…