VBA/Excel/Access/Word/Excel/Formula — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:47, 26 мая 2010
Содержание
- 1 Assigns the values 101 to 200 to the range B1:Bnd again does it more efficiently than a For...Next loop
- 2 Create a set of related formulas in a column: use a looping structure to iterate through the cells that receive the formula
- 3 Fill formula to cell
- 4 Inserts a formula in cell A11 of a worksheet that calculates the sum of the values in the range A2:A10 using the Excel application"s SUM function
- 5 Is active cell empty
- 6 The Evaluate method can also be used with arrays.
- 7 Two ways you can use Evaluate to generate a reference to a Range object, and assign a value to that object
- 8 Use Copy and Paste or AutoFill functions
- 9 Use [] to evaluate formula
Assigns the values 101 to 200 to the range B1:Bnd again does it more efficiently than a For...Next loop
Sub main()
[B1:B100] = [ROW(101:200)]
End Sub
Sub formula()
Dim formulaString As String
Dim I As Integer
Cells(1, "B").Value = Cells(1, "A").Value
For I = 2 To 10
formulaString = "=A" & Trim(str(I)) & "+B" & Trim(str(I - 1))
Cells(I, "B").formula = formulaString
Next I
End Sub
Fill formula to cell
Sub AddWatch()
With Application
.Range("A1").Formula = 1
.Range("A2").Formula = 2
.Range("A3").Formula = "=Sum(A1:A2)"
.Range("A3").Select
.Watches.Add Source:=ActiveCell
End With
End Sub
Inserts a formula in cell A11 of a worksheet that calculates the sum of the values in the range A2:A10 using the Excel application"s SUM function
Sub formal()
Dim formulaString As String
formulaString = "=SUM($A$2:$A$10)"
Cells(11, "A").Formula = formulaString
End Sub
Is active cell empty
Sub IsActiveCellEmpty()
Dim sFunctionName As String, sCellReference As String
sFunctionName = "ISBLANK"
sCellReference = ActiveCell.Address
MsgBox Evaluate(sFunctionName & "(" & sCellReference & ")")
End Sub
The Evaluate method can also be used with arrays.
Sub short()
vRowArray = [ROW(101:200)]
End Sub
Two ways you can use Evaluate to generate a reference to a Range object, and assign a value to that object
Sub evalDemo()
Evaluate("A1").value = 10
[A1].value = 10
End Sub
Use Copy and Paste or AutoFill functions
Sub autoFill()
Dim formulaString As String
Dim I As Integer
Cells(1, "B").Value = Cells(1, "A").Value
formulaString = "=A2+B1"
Cells(2, "B").formula = formulaString
End Sub
Use [] to evaluate formula
Sub isBlank()
MsgBox [ISBLANK(A1)]
End Sub