2009-10-01 5 views
0

Il s'agit d'une feuille Excel avec 4000 lignes * 200 colonnes.Entrée macro Valeur et extraction des lignes en conséquence

une colonne a 10 noms différents dans la colonne.

La fonction de ma macro est de demander d'abord le nom de la personne dont le rapport est requis. Supposons que je dis « Ram », il va extraire toutes les lignes correspondant à ce nom et enregistrer les valeurs dans le nouveau classeur et enregistrer le nom de fichier comme « Ram »

Répondre

2

Voici comment j'aborder la macro:

' 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" 
0

J'ai fait quelque chose comme ça ... cela a-t-il un sens?

 
    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
Questions connexes