简体   繁体   中英

I want to do look up on excel file to add new row in excel file in all sheet

I have one excel file with 100 sheets

My problem is I want to do 在此处输入图片说明

I want to check if I found "Name" In any "Attribute" column.

Then Add new row of record "DisplayName" with same values what "Name" having but "IsMandatory" is "N"

There are 400 sheets where I need to check and insert new row if I found "Name" in "Attribute" column

Please give me idea . How can I do it using excel lookup or pivot technique. ?

Sub Test()
Dim curWorkbook As Workbook
Dim rnge As Range
Dim pasteCell As Integer

Set curWorkbook = ThisWorkbook

For Each wrkSheet In curWorkbook.Worksheets
    wrkSheet.Activate
    pasteCell = Range("A1").End(xlDown).Row + 1
    wrkSheet.Range("A:A").Select

    Set rnge = Selection.Find(What:="Name", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

    If rnge Is Nothing Then
        '//Do Nothing
    Else
        wrkSheet.Range("A" & rnge.Row & ":D" & rnge.Row).Copy _
                    Destination:=wrkSheet.Range("A" & pasteCell & ":D" & pasteCell)
        wrkSheet.Range("A" & pasteCell).Value = "Display Name"
        wrkSheet.Range("C" & pasteCell).Value = "N"
        Set rnge = Nothing
    End If
    wrkSheet.Range("A1").Select
Next
End Sub

I am assuming the column references will remain same (A:D). If the columns will change in each individual sheet, you will have first find the correct column in the worksheet and then search for "Name" attribute in that column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM