Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2853|回复: 5

[已解决]怎样改变这个窗体列表中的格式,使它只显示日期而不显示时间?

[复制链接]
发表于 2010-2-5 10:08 | 显示全部楼层 |阅读模式

怎样改变这个窗体列表中的格式,使它只显示日期而不显示时间?

 

gZyA3arf.rar (40.89 KB, 下载次数: 23)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2010-2-5 10:16 | 显示全部楼层

改一下代码:

Sub 列表框显示()
Dim i As Long
Dim j As Long
    On Error Resume Next
    UserForm2.ListBox1.Clear
    UserForm2.ListBox1.ColumnCount = 8
    With Sheets("结果显示")
        .Range("F2:F" & .[a65536].End(3).Row) = .Range("F2:F" & .[a65536].End(3).Row).Value '转化为数值
        For i = 1 To .[a65536].End(3).Row
            UserForm2.ListBox1.AddItem
            For j = 1 To 8
                If j = 2 Then
                  UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = Format(.Cells(i, j), "yyyy-m-d")
                Else
                  UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = .Cells(i, j)
                End If
            Next j
        Next i
        UserForm2.ListBox1.ColumnWidths = "52;52;42;100;25;28;26;40"
     End With
End Sub


回复

使用道具 举报

发表于 2010-2-5 10:17 | 显示全部楼层

加个判断,设置一下格式

 If j = 2 Then
                  UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = Format(.Cells(i, j), "yyyy-m-d")
                Else
                  UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = .Cells(i, j)
                End If

回复

使用道具 举报

发表于 2010-2-5 10:23 | 显示全部楼层    本楼为最佳答案   

列表框显示的语句改一下


Sub 列表框显示()
Dim i As Long
Dim j As Long
    On Error Resume Next
    UserForm2.ListBox1.Clear
    UserForm2.ListBox1.ColumnCount = 8
    With Sheets("结果显示")
        .Range("F2:F" & .[a65536].End(3).Row) = .Range("F2:F" & .[a65536].End(3).Row).Value '转化为数值
        For i = 1 To .[a65536].End(3).Row
            UserForm2.ListBox1.AddItem
            For j = 1 To 8
                If i > 1 And j = 2 Then
                    UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = Format(.Cells(i, j), "yyyy-m-d")
                Else
                    UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = .Cells(i, j)
                End If
            Next j
        Next i
        UserForm2.ListBox1.ColumnWidths = "52;52;42;100;25;28;26;40"
     End With
End Sub
回复

使用道具 举报

发表于 2010-2-5 10:30 | 显示全部楼层

好复杂啊,看不懂
回复

使用道具 举报

 楼主| 发表于 2010-2-5 10:37 | 显示全部楼层

QUOTE:
以下是引用amulee在2010-2-5 10:23:00的发言:

列表框显示的语句改一下


Sub 列表框显示()
Dim i As
  Long
Dim j As
  Long
    On
  Error
  Resume
  Next
    UserForm2.ListBox1.Clear
    UserForm2.ListBox1.ColumnCount = 8
    With Sheets("结果显示")
        .Range("F2:F" & .[a65536].End(3).Row) = .Range("F2:F" & .[a65536].End(3).Row).Value '转化为数值
        For i = 1 To .[a65536].End(3).Row
            UserForm2.ListBox1.AddItem
            For j = 1 To 8
                If i > 1 And j = 2 Then
                    UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = Format(.Cells(i, j), "yyyy-m-d")
                Else
                    UserForm2.ListBox1.List(UserForm2.ListBox1.ListCount - 1, j - 1) = .Cells(i, j)
                End
  If
            Next j
        Next i
        UserForm2.ListBox1.ColumnWidths = "52;52;42;100;25;28;26;40"
     End
  With
End
  Sub

谢谢版主"一针见血"的解决方案,问题解决啦

[em01]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-16 19:13 , Processed in 0.202391 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表