分享

来自【Excel完美论坛】

 刀丛里觅诗 2016-06-15
正在加载...
头像

佛山小老鼠

昨天 22:06

楼主

【 Excel分享】快速录入数据工具(附源代码)



Private Declare Function GetDC Lib 'user32.dll' (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib 'gdi32.dll' (ByVal HDC As Long, ByVal nIndex As Long) As Long
Private Declare Function ReleaseDC Lib 'user32.dll' (ByVal hwnd As Long, ByVal HDC As Long) As Long


Private Const LOGPIXELSX   As Long = 88
Private Function PointsPerPixel() As Double


    Dim HDC As Long
    Dim lngPotsPerInch As Long
    HDC = GetDC(0)
    lngPotsPerInch = GetDeviceCaps(HDC, LOGPIXELSX)
    PointsPerPixel = Application.InchesToPoints(1) / lngPotsPerInch
    ReleaseDC 0, HDC
End Function


Private Sub Worksheet_SelectionChange(ByVal T As Range)


    Dim rng As Range, x As Single, y As Single, DZoom As Single
    If T.Column = 2 And T.Count = 1 Then
  Set rng = ActiveCell
  With ActiveWindow
   DZoom = .Zoom / 100
   x = .PointsToScreenPixelsX((rng.Left + rng.Width) / PointsPerPixel * DZoom)
   y = .PointsToScreenPixelsY((rng.Top) / PointsPerPixel * DZoom)
  End With


  With 界面
   If .Visible = False Then .Show 0
   .Move x * PointsPerPixel, y * PointsPerPixel
  End With
  Set rng = Nothing
    Else
  Unload 界面
    End If
End Sub


Option Explicit


Private Sub CommandButton1_Click()
   Dim arr1, x, k, arr2(), kk, y
   On Error GoTo 100
   arr1 = Sheets('快捷录入数据源').Range('A1').CurrentRegion
   For x = 1 To UBound(arr1)
  If VBA.InStr(1, arr1(x, 1), Me.TextBox1.Text) <> 0 Then
   k = k + 1
  End If
   Next x
   ReDim arr2(1 To k, 1 To UBound(arr1, 2))
   For x = 1 To UBound(arr1)
   If VBA.InStr(1, arr1(x, 1), Me.TextBox1.Text) <> 0 Then
   kk = kk + 1
   For y = 1 To UBound(arr1, 2)
    arr2(kk, y) = arr1(x, y)
   Next y
  End If
   Next x
   With Me.ListBox1
  .ColumnCount = UBound(arr1, 2)
  .List = arr2
  .ColumnWidths = '2厘米;1厘米;1厘米;1厘米'
    End With
    Exit Sub
100:
    MsgBox '搜索不到: ' & Me.TextBox1.Text
    Me.TextBox1 = ''
End Sub


Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim a, z
    a = Me.ListBox1.ListIndex
    For z = 1 To 4
  ActiveCell.Offset(0, z - 1) = Me.ListBox1.List(a, z - 1)
    Next z


End Sub


立即关注
11

全部回复

只看楼主 倒序排列

头像 影风 LV2 2楼


感谢楼主的无私分享!

昨天 22:23

头像 天天好心情 LV2 3楼

谢谢老鼠老师

昨天 22:23

头像 蒲公英 LV2 4楼

好东西,赶紧收藏

昨天 22:24

头像 尘封记忆 LV2 5楼

这个有用

昨天 22:24

正在加载...

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多