如果不为null,则连接单元格值

时间:2015-09-14 21:43:08

标签: excel vba excel-vba

我正在创建演示中间值定理的VBA宏。

用户输入制定术语的术语并打印到相应的行和C列。

如果此行不为null(包含Term),则该Term应连接到Polynomial(所有Term连接)。这怎么用宏?

到目前为止

代码。

Option Explicit

Sub Function1()
Dim Polynomial As String
Dim Sign
Dim RowCounter As Integer
Dim Degree
Dim Coefficient
Dim Term As String
Dim Variable

RowCounter = 1
While Cells(RowCounter, 1).Value <> "" And Cells(RowCounter, 2).Value <> "" ' as long as there is a coefficient and degree
MsgBox "Enter polynomial by terms."
Variable = InputBox("Enter variable (x, y, z, etc.).")
Degree = Cells(RowCounter, 1).Value 'A2 and down

If (Coefficient < 0) Then
Sign = " - " ' if coefficient negative
Else
If Coefficient > 0 Then Sign = " + " ' if coefficient positive
End If

Term = Sign & Coefficient & Variable & "^" & Degree = Cells(RowCounter + 1, 3).Value ' C2 and down
While Cells(RowCounter, 3).Value <> "" ' as long as there is a term
    'Polynomial=all polynomials combined
RowCounter = RowCounter + 1
Wend

RowCounter = 1 ' reset row counter
While Cells(RowCounter, 3).Value <> "" ' as long as there is a term
MsgBox "Combining like terms to form polynomial."
RowCounter = RowCounter + 1
Wend
MsgBox Polynomial
End Sub

0 个答案:

没有答案