General discussion

  • Creator
    Topic
  • #2280754

    Excel Template

    Locked

    by dhilliard ·

    I am trying to create a macro that will run when a worksheet is opened and automatically insert a row every fourth row. The data is queried in a database and exported to Excel, and I need it separated. Some worksheets may only have 10 lines of data, but others may have 200. How do I tell it to do this? I am a newbie at VB, but that looks like the place to do it. Thanks for any help anyone can provide.

All Comments

  • Author
    Replies
    • #3365430

      Reply To: Excel Template

      by d_gilmour_1978 ·

      In reply to Excel Template

      this code will insert a row every 4th row (you can change this by changing the mod 4 to mod 5 etc

      Sub Macro1()
      Sheets(1).Select
      x = 1
      While Cells(x, 1).Value <> “”
      If x Mod 4 = 0 Then
      Rows(x).Select
      Selection.Insert Shift:=xlDown
      End If
      x = x + 1
      Wend

      End Sub

      if you need any further assistance please repost via comments

Viewing 0 reply threads