Results 1 to 3 of 3

Thread: Macro to find a value within a cell and insert lines

  1. #1

    Macro to find a value within a cell and insert lines



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Good afternoon,

    I need a snippet of code that will run down column A and find a value, I'll call it 'x'. At x, I would like to insert lines (preferably an input box would ask the user the number of rows) with x remaining on the bottom after the insertion. X will be a unique value and will be the only contents of the cell. After this I think I can handle the rest .

    Thanks in advance,

  2. #2
    Magician NoS's Avatar
    Join Date
    Jan 2013
    Location
    British Columbia
    Posts
    722
    Articles
    0
    Excel Version
    Excel 2010 64bit
    Maybe something like this?
    Code:
    Sub Insert_Rows()
        Dim x
        Dim y
        Dim InsertSpot
        
        x = "string to find"
        
        On Error Resume Next
        InsertSpot = Application.Match(x, Columns("A:A"), 0)
        On Error GoTo 0
        
        If IsError(InsertSpot) Then
            MsgBox "Didn't find  " &  x
        Else
            y = InputBox("Rows to insert")
            Range("A" & InsertSpot).EntireRow.Resize(y).Insert
        End If
    End Sub

  3. #3
    Beautiful :-), Thanks.

Posting Permissions

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