अनुमानित पढ्ने समय: 3 मिनुटी
निम्न उप प्रक्रियाले सक्रिय कार्यपत्रको स्तम्भ A मा कक्षहरूबाट मानहरू पढ्छ, जबसम्म यो खाली कक्षको सामना गर्दैन। मानहरू एरेमा भण्डारण गरिएका छन्। यो सरल एक्सेल म्याक्रो उदाहरणको प्रयोगलाई चित्रण गर्दछ:
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 array जानकारी राख्न पर्याप्त ठूलो छ भनी जाँच गर्दछ, यदि छैन भने, 10 ले array को आकार बढाउन ReDim प्रयोग गर्नुहोस्।dCellValues(iRow) = Cells(iRow, 1).Value
" CellValues array मा हालको सेल भण्डारण गर्दछनिम्न उप प्रक्रियाले "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
गत सोमबार, फाइनान्सियल टाइम्सले OpenAI सँग सम्झौताको घोषणा गर्यो। FT ले आफ्नो विश्व स्तरीय पत्रकारिता लाई लाइसेन्स...
लाखौं मानिसहरूले स्ट्रिमिङ सेवाहरूको लागि भुक्तानी गर्छन्, मासिक सदस्यता शुल्क तिर्छन्। यो आम धारणा छ कि तपाईं…
Veeam द्वारा Coveware ले साइबर जबरजस्ती घटना प्रतिक्रिया सेवाहरू प्रदान गर्न जारी राख्नेछ। Coveware ले फोरेन्सिक र उपचार क्षमताहरू प्रदान गर्दछ ...
अनुमानित मर्मतसम्भारले तेल र ग्यास क्षेत्रमा क्रान्तिकारी परिवर्तन गर्दैछ, बिरुवा व्यवस्थापनको लागि एक नवीन र सक्रिय दृष्टिकोणको साथ।…