宏vb从过滤器获取值

时间:2017-03-20 03:19:19

标签: excel vba excel-vba

在这种情况下

现在我已经有了一个记录名字,姓氏,鲜血,性别,分部......的按钮 发送至“เก็บข้อมูล”页面//表示保存数据页面

按ID自动过滤,然后转到“เก็บข้อมูล”页面

我希望显示按绿色方块主页单元格A14中的ID显示过滤的值

"เก็บข้อมูล"Page

Main Page.Page

记录代码

Sub Get_Information()
Dim Lrow  As Integer
Lrow = Sheets(5).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

Name = Sheets(1).Cells(5, 4).Value
LastName = Sheets(1).Cells(5, 5).Value
Blood = Sheets(1).Cells(6, 4).Value
Position = Sheets(1).Cells(7, 4).Value
Gender = Sheets(1).Cells(8, 4).Value
Division = Sheets(1).Cells(9, 4).Value
ID = Sheets(1).Cells(3, 5).Value
Medicine = Sheets(1).Cells(6, 7).Value
MedicalItem = Sheets(1).Cells(7, 7).Value
Symtom = Sheets(1).Cells(5, 7).Value
ValueMedicine = Sheets(1).Cells(6, 8).Value
ValueMedicalItem = Sheets(1).Cells(7, 8).Value
 Sheets(5).Cells(Lrow, 1).Value = Date
 Sheets(5).Cells(Lrow, 2).Value = Time
 Sheets(5).Cells(Lrow, 3).Value = ID
 Sheets(5).Cells(Lrow, 4).Value = Name
 Sheets(5).Cells(Lrow, 5).Value = LastName
 Sheets(5).Cells(Lrow, 6).Value = Blood
 Sheets(5).Cells(Lrow, 7).Value = Gender
 Sheets(5).Cells(Lrow, 8).Value = Position
 Sheets(5).Cells(Lrow, 9).Value = Division
 Sheets(5).Cells(Lrow, 10).Value = Symtom
 Sheets(5).Cells(Lrow, 11).Value = Medicine
 Sheets(5).Cells(Lrow, 12).Value = ValueMedicine
 Sheets(5).Cells(Lrow, 13).Value = MedicalItem
 Sheets(5).Cells(Lrow, 14).Value = ValueMedicalItem
 MsgBox "Record Successful"


  Sheets("เก็บข้อมูล").Range("$C$1:$C$67").AutoFilter Field:=1, Criteria1:=Sheets("Main Page").Range("e3").Value

If ActiveSheet.Name = "Main Page" Then
    Worksheets("เก็บข้อมูล").Activate
Else
    Worksheets("Main Page").Activate
End If


End Sub

代码按钮删除

Sub Delete()

[G6,D6,G7,H6,H7,G5].ClearContents

Sheets("Main Page").Range("A14:M333").ClearContents
End Sub

Excel File

链接Excel文件VB密码:游戏

1 个答案:

答案 0 :(得分:1)

您可以在.AutoFilter

之后复制过滤后的数据
ThisWorkbook.Worksheets("เก็บข้อมูล").UsedRange.Offset(1).Copy
ThisWorkbook.Worksheets("Main Page").Range("A14").PasteSpecial
Application.CutCopyMode = False