Вариант вывода суммы модулей в ячейку с помощью пользовательской формы.
| Код |
|---|
Option Explicit
'v2
Private Sub CommandButton1_Click()
ActiveCell.Formula = ConnectText
End Sub
Private Function ConnectText() As String
Dim cb As Object, ss As String, iCount As Long
ss = "="
For Each cb In GetControlColection("TextBox")
iCount = iCount + 1
If IsNumeric(cb.Value) Then
If iCount Mod 2 = 1 Then
ss = ss & "+ABS("
End If
If cb.Value >= 0 Then
ss = ss & "+" & cb.Value
Else
ss = ss & cb.Value
End If
If iCount Mod 2 <> 1 Then
ss = ss & ")"
End If
End If
Next
ConnectText = ss
End Function
Private Function GetControlColection(sTypeName As String) As Collection
Dim col As New Collection
Dim cb As Control
For Each cb In Me.Controls
If TypeName(cb) = sTypeName Then
col.Add cb
End If
Next
Set GetControlColection = col
End Function
|
Изменено: - 06.03.2026 16:35:12