VB/VBA worksheet_selectchange事件_参数传递

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB/VBA worksheet_selectchange事件_参数传递相关的知识,希望对你有一定的参考价值。

vb参数传递2种:1传值byval2传址byref 按值传递,传递其实引用象副本,传递程更改并影响原象,按址传递,传递才真原象,更改导致原引用象更改 execl VBAworksheet_selectchange事件其传递参数Target说明清楚byval即传值 Target所更改都能显现呢

参考技术A target
定义象
Worksheet_SelectionChange(ByVal
Target
As
Range)
定义
range
类型类型象
于参数引用象情况改变象属性

VBA练习-打开文件,添加选中项,生成新表

学习VBA,正好给财务制作一个小工具:

 

Sub 打开人员信息表()
    Dim wb As Workbook, c As Integer
    Set wb = Workbooks.Open("C:\Users\wzn\Documents\工作簿2.xlsx", 0, True)
    c = wb.Worksheets.Count
    If c < 3 Then wb.Worksheets.Add after:=Worksheets(Worksheets.Count)
    wb.Worksheets(1).Select
    
End Sub


Sub 添加选中人员()
    Dim fw As Worksheet, lw As Worksheet, fr As Integer, lr As Integer, rg As Range
    Set fw = ActiveSheet
    Set lw = Worksheets(Worksheets.Count)
    For Each rg In Selection
        fr = rg.Row
        If Range("a" & fr) = "" Or Range("b" & fr) = "" Then
            MsgBox "选中项不能是空值,请确认选中项后重试"
            Exit Sub
        End If
        lr = lw.Range("a65536").End(xlUp).Row + 1
        lw.Range("a" & lr) = Range("a" & fr)
        lw.Range("b" & lr) = Range("b" & fr)
    Next
    If lw.Range("a1") <> "姓名" Then
        lw.Range("a1") = "姓名"
        lw.Range("b1") = "卡号"
        lw.Range("c1") = "金额"
        
        With lw.Range("a1,b1,c1").Font
            .Name = "宋体"
            .Size = 12
            .Bold = True
        End With
    End If
    With lw.Range("a1").CurrentRegion
        .Borders.ColorIndex = 1
        .Columns.AutoFit
        .HorizontalAlignment = xlCenter
    End With
End Sub

Sub 导出添加人员()
    Dim lw As Worksheet, curBook As Workbook
    Set curBook = ActiveWorkbook
    Set lw = Worksheets(Worksheets.Count)
    lw.Move
    curBook.Close False
End Sub

 

以上是关于VB/VBA worksheet_selectchange事件_参数传递的主要内容,如果未能解决你的问题,请参考以下文章

Excel VBA 复制

[VBA]批量新建指定名称的工作表

类worksheet的paste方法无效?VBA 怎么修改啊

vba应用

vb给excel添加工作表

VBA练习-打开文件,添加选中项,生成新表