VBA Excel to add ROW with phrase given condition of a phrase in ROW

Hi Guys,

Need help to achieve this.

I have multiple lines of repeated phrase, i.e,

interface A
interface B
interface C
interface D
interface E

I need to insert phrase "set foo" to a new ROW after the each ROW of "interface" string to become:

interface A
set foo
interface B
set foo
interface C
set foo
interface D
set foo
interface E
set foo

Can you help me finding the solution.

Comments

  • Hello!
    I can suggest such decision (maybe not optimal, with attached example):



    Private Sub CommandButton1_Click()
    Dim intI, intCount As Integer
    Dim strPhrase As String
    strPhrase = "set foo"
    intI = 1
    'count and copy all phrases into second column
    While Cells(intI, 1) <> ""
    Cells(intI, 2) = Cells(intI, 1)
    intI = intI + 1
    Wend
    intCount = intI - 1
    'inserting phrase:
    For intI = 1 To intCount
    Cells(2 * intI - 1, 1) = Cells(intI, 2)
    Cells(2 * intI, 1) = strPhrase
    Next intI
    'clear second column
    Columns("B:B").ClearContents
    End Sub

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion