VBA获取5个整数列表中的前2个整数值



我的代码有五个整数值,这些值是从一些文本框中获取的。

Dim a, b, c, d, e As Integer
a=CInt(frmform.textbox1.text)
b=CInt(frmform.textbox2.text)
c=CInt(frmform.textbox3.text)
d=CInt(frmform.textbox4.text)
e=CInt(frmform.textbox5.text)

我想比较这五个值并获得前两个值,以便我可以将变量的原始描述打印到我的两个输出文本框中,如下所示:

假设a和b是最上面的两个整数,它们的描述是a = High Growth Leader和b = Niche Business Leader。所以我想在我的输出文本框中打印它们的描述,如下所示。

frmform.TextBox1.Text="The first role is High Growth Leader"
frmform.TextBox2.Text="The second top role is Niche Business Leader"

如何用最简单的方法实现这一点。

我用下列方法解决了这个问题,

  1. 我创建了一个新表,并在列1
  2. 中添加了变量描述。
  3. 在代码中,我将各自的变量值分配给第2列
  4. 中的描述。
  5. 通过扩展列1,记录marco从最高到最低值对列2进行排序。下面是代码
Sub Score_sort()
'
' Score_sort Macro
Range("C100:C104").Select
ActiveWorkbook.Worksheets("Competency Scoring").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Competency Scoring").Sort.SortFields.Add2 Key:= _
Range("C100"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Competency Scoring").Sort
.SetRange Range("B100:C104")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
  1. 现在我已经按降序排序了描述值对,在代码中我写了下面的代码,从工作表中取出前两个描述,并将其放在文本框中。
frmform.TextBox31.Text = Sheet2.Cells(100, 2).Value
frmform.TextBox32.Text = Sheet2.Cells(101, 2).Value 

最新更新