Consulting

Results 1 to 5 of 5

Thread: Insert cell at specific rows by string

  1. #1

    Insert cell at specific rows by string

    Hello everyone


    I have a string say s="11,19" in a code
    How can I insert cell down at those rows 11 and 19 in column G for example.. and insert specific text after insert .. and also at the first empty row after last cell in the same column?

    Help.jpg

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi YasserKhalil
    Sub test()
    Dim arr, s$, i&, r&, r1&
    arr = Array(11, 19)
    s = "Tot."
    r1 = 1
    For i = 0 To UBound(arr)
      r = arr(i) + 1
      Cells(r, "g").Resize(, 2).Insert Shift:=xlDown
      Cells(r, "g").Resize(, 2) = Array(s, "=sum(h" & r1 & ":h" & r - 1 & ")")
      r1 = r + 1
    Next i
    r = Cells(Rows.Count, "g").End(3).Row
    Cells(r + 1, "g").Resize(, 2) = Array(s, "=sum(h" & r1 & ":h" & r & ")")
    End Sub

  3. #3
    Thanks a lot for your help. It seems no way of looping. Is there a way to do such stuff without looping?

  4. #4
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    This loop is not in cells, it's in conditions array.
    There's no way not to loop, unless you have only one condition.
    If my code doesn't work, please refer to the attachment.
    Attached Files Attached Files

  5. #5
    It is working well. Thank you very much for your great help.

Posting Permissions

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