宏输入值并相应地提取行

时间:2009-10-01 01:23:40

标签: excel

这是一个包含4000行* 200列的Excel工作表。

一列中有10个不同的名称。

我的宏的功能是首先询问需要报告的人的姓名。假设我说“Ram”它将提取所有等于该名称的行并将值保存在新工作簿中并将文件名保存为“Ram”

2 个答案:

答案 0 :(得分:2)

这就是我接近宏的方式:

' Prompt the user for a name '
Name = PromptForName

' Get your sheets (and create a new workbook) '
Set Src = ActiveSheet
Set Book2 = Workbooks.Add
Set Dst = Book2.Sheets(1)

' Copy headers from row 1 '
Src.Rows(1).Copy
Dst.Rows(1).PasteSpecial

' Assuming column A is your name column '
For Each cell In Src.Range("A2:A" & Src.UsedRange.Rows.Count).Cells
    If cell.Value = Name Then
        Src.Rows(cell.Row).Copy
        Dst.Rows(2).Insert Shift:=xlShiftDown
    End If
Next

' Specify path to save (with name) '
Book2.SaveAs Name & ".xls"

答案 1 :(得分:0)

我做过这样的事情......这有什么意义吗?

    Sub valueMacro()

    Dim VariableSheetName As String

    Workbooks.Add

    VariableSheetName = InputBox("Sheet Name", "Enter sheet name", "")

    ActiveWorkbook.SaveAs "T:\1AA\" & VariableSheetName 

    Dim strvalue As String
    strvalue = InputBox("Enter the name of FM")

    Dim wksDisc As Worksheet

    '' Set wksDisc = Sheets("T:\1AA\" & VariableSheetName)
     If Target.Column = E And Target.Value = strvalue Then
       Target.EntireRow.Copy
       wksDisc.Paste Destination:=wksDisc.Cells(Target.Row, 1)
       Application.CutCopyMode = False
     End If

    End Sub