ਅਨੁਮਾਨਿਤ ਪੜ੍ਹਨ ਦਾ ਸਮਾਂ: 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 ਐਰੇ ਜਾਣਕਾਰੀ ਰੱਖਣ ਲਈ ਕਾਫੀ ਵੱਡਾ ਹੈ, ਜੇਕਰ ਨਹੀਂ, ਤਾਂ ਐਰੇ ਦੇ ਆਕਾਰ ਨੂੰ 10 ਤੱਕ ਵਧਾਉਣ ਲਈ ReDim ਦੀ ਵਰਤੋਂ ਕਰੋ।dCellValues(iRow) = Cells(iRow, 1).Value
" ਮੌਜੂਦਾ ਸੈੱਲ ਨੂੰ CellValues ਐਰੇ ਵਿੱਚ ਸਟੋਰ ਕਰਦਾ ਹੈਹੇਠ ਦਿੱਤੀ ਉਪ ਵਿਧੀ “ਸ਼ੀਟ2” ਨਾਮਕ ਵਰਕਸ਼ੀਟ ਦੇ ਕਾਲਮ 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
Veeam ਦੁਆਰਾ Coveware ਸਾਈਬਰ ਜ਼ਬਰਦਸਤੀ ਘਟਨਾ ਪ੍ਰਤੀਕਿਰਿਆ ਸੇਵਾਵਾਂ ਪ੍ਰਦਾਨ ਕਰਨਾ ਜਾਰੀ ਰੱਖੇਗਾ। ਕੋਵਵੇਅਰ ਫੋਰੈਂਸਿਕ ਅਤੇ ਉਪਚਾਰ ਸਮਰੱਥਾਵਾਂ ਦੀ ਪੇਸ਼ਕਸ਼ ਕਰੇਗਾ...
ਪੂਰਵ-ਅਨੁਮਾਨਤ ਰੱਖ-ਰਖਾਅ ਪਲਾਂਟ ਪ੍ਰਬੰਧਨ ਲਈ ਇੱਕ ਨਵੀਨਤਾਕਾਰੀ ਅਤੇ ਕਿਰਿਆਸ਼ੀਲ ਪਹੁੰਚ ਦੇ ਨਾਲ, ਤੇਲ ਅਤੇ ਗੈਸ ਸੈਕਟਰ ਵਿੱਚ ਕ੍ਰਾਂਤੀ ਲਿਆ ਰਹੀ ਹੈ।…
UK CMA ਨੇ ਨਕਲੀ ਖੁਫੀਆ ਮਾਰਕੀਟ ਵਿੱਚ ਬਿਗ ਟੈਕ ਦੇ ਵਿਵਹਾਰ ਬਾਰੇ ਇੱਕ ਚੇਤਾਵਨੀ ਜਾਰੀ ਕੀਤੀ ਹੈ. ਉੱਥੇ…
"ਕੇਸ ਗ੍ਰੀਨ" ਫਰਮਾਨ, ਯੂਰਪੀਅਨ ਯੂਨੀਅਨ ਦੁਆਰਾ ਇਮਾਰਤਾਂ ਦੀ ਊਰਜਾ ਕੁਸ਼ਲਤਾ ਨੂੰ ਵਧਾਉਣ ਲਈ ਤਿਆਰ ਕੀਤਾ ਗਿਆ ਹੈ, ਨੇ ਆਪਣੀ ਵਿਧਾਨਕ ਪ੍ਰਕਿਰਿਆ ਨੂੰ ਇਸ ਦੇ ਨਾਲ ਸਮਾਪਤ ਕੀਤਾ ਹੈ ...