Consulting

Results 1 to 6 of 6

Thread: Find word insert formula

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Find word insert formula

    Bom dia!!

    Hi.
    I need find a word (all columns in row 1), after (below row 2), insert fomula.

    Cross-Post
    http://www.excelforum.com/search.php?searchid=2913371
    Sub Find_InsertFormula() 
        Dim lr As Long
        'Call Find_First
        Application.ScreenUpdating = False
    
        With Sheets("Plan1")
            lr = .Cells(.Rows.Count, "A").End(xlUp).Row - 1
            .ActiveCell.Formula = "=1+1+1"
            .ActiveCell.AutoFill .ActiveCell.Resize(lr - 1)
        End With
        Application.ScreenUpdating = True End Sub
    Sub Find_First()    
    Dim FindString As String
        Dim Rng As Range
        FindString = "Atual"
        If Trim(FindString) <> "" Then
            With Sheets("Plan1").Range("A1:Q1")
                Set Rng = .Find(What:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                    Application.Goto Rng.Offset(2, 1), True
                Else
                    MsgBox "Não encontrado"
                End If
            End With
        End If End Sub

    Att
    Attached Files Attached Files
    Last edited by marreco; 05-23-2014 at 12:48 PM.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by marreco View Post
    I need find a word (all columns in row 1), after (below row 2), insert fomula.
    hi.

    try this:
    Sub Find_Insert()    Dim Rng As Range
        Dim LastRow As Long
        With Sheets("Plan1")
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
            Set Rng = .Rows(1).Find("Atual")
            If Not Rng Is Nothing Then
                .Range(.Cells(3, Rng.Column), .Cells(LastRow, Rng.Column)).Formula = "=1+1+1"
            Else
                MsgBox "Não encontrado"
            End If
        End With
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi

    Very very good, I'll do the test, then topic as solved.

    thank you very much!!!

  4. #4
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.

    Thank you!!!

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you're welcome.

    if you're sure the word "Atual" exists in row 1, it can be done with a one liner.

    Sub Find_Insert_2()
        With Sheets("Plan1")
            .Rows(1).Find("Atuals").Offset(2).Resize(.Cells(.Rows.Count, "A").End(xlUp).Row - 2).Formula = "=1+1+1"
        End With
    End Sub
    if "Atual" does not exist in row 1, above code will throw RTE 91, "Object variable or With block variable not set" error.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  6. #6
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi. mancumbus, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •