ເວລາອ່ານໂດຍປະມານ: 3 ນາທີ
ຂັ້ນຕອນຍ່ອຍຕໍ່ໄປນີ້ຈະອ່ານຄ່າຈາກເຊລໃນຖັນ A ຂອງແຜ່ນວຽກທີ່ເຮັດວຽກຢູ່, ຈົນກວ່າມັນຈະພົບກັບຕາລາງຫວ່າງເປົ່າ. ຄ່າຖືກເກັບໄວ້ໃນອາເຣ. ຕົວຢ່າງ macro Excel ງ່າຍໆນີ້ສະແດງໃຫ້ເຫັນເຖິງການໃຊ້:
Do Until
;Ubound
buildin (ເຊິ່ງສົ່ງຄືນດັດຊະນີສູງສຸດຂອງອາເຣ).' 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 array ມີຂະຫນາດໃຫຍ່ພໍທີ່ຈະເກັບຂໍ້ມູນ, ຖ້າບໍ່ແມ່ນ, ໃຊ້ ReDim ເພື່ອເພີ່ມຂະຫນາດຂອງ array ໂດຍ 10.dCellValues(iRow) = Cells(iRow, 1).Value
” ເກັບຮັກສາເຊັລປະຈຸບັນຢູ່ໃນ CellValues arrayຂັ້ນຕອນຍ່ອຍຕໍ່ໄປນີ້ຈະອ່ານຄ່າຈາກຖັນ A ຂອງແຜ່ນງານທີ່ມີຊື່ວ່າ "Sheet2" ແລະປະຕິບັດການຄິດໄລ່ກ່ຽວກັບຄ່າຕ່າງໆ. ຄ່າທີ່ໄດ້ຮັບແມ່ນພິມຢູ່ໃນຖັນ 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
ໃຫ້ຂຽນ Macro 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
ບັນທຶກປື້ມບັນທຶກວຽກດ້ວຍການເປີດໃຊ້ macros (ຕົວຢ່າງ, ເປັນໄຟລ໌ .xlsm).
ດຽວນີ້, ທຸກໆຄັ້ງທີ່ພວກເຮົາອັບເດດຕາລາງໃນຖັນ B (ຈາກແຖວທີ 1 ຫາແຖວທີ 10), ຕາລາງໃນຖັນ A ຈະສະແດງວັນທີ ແລະເວລາປັດຈຸບັນໂດຍອັດຕະໂນມັດ.
Ercole Palmeri
Coveware ໂດຍ Veeam ຈະສືບຕໍ່ໃຫ້ບໍລິການຕອບໂຕ້ເຫດການ extortion cyber. Coveware ຈະສະ ເໜີ ຄວາມສາມາດດ້ານນິຕິສາດແລະການແກ້ໄຂ…
ການຮັກສາການຄາດເດົາແມ່ນການປະຕິວັດຂະແໜງນ້ຳມັນ ແລະ ອາຍແກັສ, ດ້ວຍແນວທາງນະວັດຕະກໍາ ແລະ ຕັ້ງໜ້າໃນການຄຸ້ມຄອງພືດ.…
CMA ຂອງອັງກິດໄດ້ອອກຄໍາເຕືອນກ່ຽວກັບພຶດຕິກໍາຂອງ Big Tech ໃນຕະຫຼາດປັນຍາປະດິດ. ຢູ່ທີ່ນັ້ນ…
ດຳລັດ “Case Green” ທີ່ສ້າງຂຶ້ນໂດຍສະຫະພາບເອີລົບ ເພື່ອຍົກສູງປະສິດທິພາບດ້ານພະລັງງານຂອງຕຶກອາຄານ, ໄດ້ສິ້ນສຸດຂະບວນການນິຕິບັນຍັດຂອງຕົນດ້ວຍ…