如何按相反的顺序排序年份? [英] How to sort year in reverse order?
问题描述
我是VBA编码新手。我刚刚创建了一个程序,我在其中创建了一个Userform,其中有三个ComboBox即日,月和年。
我成功地设法填补了所需的数据。在ComboBoxYear中,下拉年份开始时最少(即1960年,我保留),并以当前年份(即2017年)结束。
我想从2017年开始更改此下拉列表,并继续减少到1960年。
以下是我为DDMMYYY输入编码的代码部分。
我尝试过:
私有 Sub UserForm_Initialize()
Dim i 作为 整数
使用 UserForm1
对于 i = 1 至 31
.ComboBoxDay.AddItem(i)
下一页
结束 使用
Dim ctr 作为 长
对于 ctr = 1 要 12
Me .ComboBoxMonth.AddItem格式(DateSerial(YYYY,ctr,DD), mmm)
下一步 ctr
使用 UserForm1
对于 i = 1960 2017
.ComboBoxYear.AddItem(i)
下一步
结束 使用
结束 Sub
试试这个
With UserForm1
对于 i = 2017 到 1960 Step -1
.ComboBoxYear.AddItem(i)
下一步
结束 使用
Hi,
I am new to VBA coding. I just made a program where I created a Userform having three ComboBox viz., Day, Month and Year.
I have successfully managed to fill those with required data. In ComboBoxYear, the dropdown year starts with least (i.e., 1960, which I have kept), and ends with current year (i.e., 2017).
I want to change this dropdown list, starting from 2017, and goes on decreasing till 1960.
Below is the code part where I have coded for inputs for DDMMYYY.
What I have tried:
Private Sub UserForm_Initialize()
Dim i As Integer
With UserForm1
For i = 1 To 31
.ComboBoxDay.AddItem (i)
Next
End With
Dim ctr As Long
For ctr = 1 To 12
Me.ComboBoxMonth.AddItem Format(DateSerial(YYYY, ctr, DD), "mmm")
Next ctr
With UserForm1
For i = 1960 To 2017
.ComboBoxYear.AddItem (i)
Next
End With
End Sub
Try this
With UserForm1 For i = 2017 To 1960 Step -1 .ComboBoxYear.AddItem (i) Next End With
这篇关于如何按相反的顺序排序年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!