+ Reply to Thread
Results 1 to 2 of 2

Add 5 rows for each row using VBA Macros

  1. #1
    Registered User
    Join Date
    04-17-2021
    Location
    India
    MS-Off Ver
    2019
    Posts
    1

    Add 5 rows for each row using VBA Macros

    Hi All i have two worksheets from Sheet1 i am copying to Sheet2 which copy data to each row once now i want my data should be look like "To be Version" :
    First column willvbe repeated 5 time and other column should be only once

    I am using Macros to do this

    Current Version
    Sheet1
    Test1 Test2 Test3
    1 1 1
    2 2 2
    3 3 3

    Sheet2
    L1 L2 L3
    1 1 1
    2 2 2
    3 3 3



    To be Version
    Sheet1
    Test1 Test2 Test3
    1 1 1
    2 2 2
    3 3 3

    Sheet2
    L1 L2 L3
    1 1 1
    1
    1
    1
    1
    2 2 2
    2
    2
    2
    2
    3 3 3
    3
    3
    3
    3
    3

    Function getLastRow(targetSheet As Worksheet, colLetter As String) As Integer
    Dim lastRow As Integer
    With targetSheet
    getLastRow = .Cells(.Rows.count, colLetter).End(xlUp).Row
    End With
    End Function

    Function getColumn(targetSheet As Worksheet, FindWord As String, Optional iRow As Integer = 1) As Integer
    Dim iCol As Integer
    Dim tmpString As String
    For iCol = 1 To getLastColumn(targetSheet, 2)
    'targetSheet.Activate
    tmpString = VBA.Replace(targetSheet.Cells(iRow, iCol).Value, "", "")
    If VBA.InStr(1, VBA.LCase(tmpString), VBA.Replace(VBA.LCase(FindWord), "", "")) Then
    getColumn = iCol
    Exit Function
    End If
    Next iCol

    End Function




    sRow = getLastRow(wsAR, "E") + 1
    LRow = getLastRow(wsRaw, "A")

    For x = 2 To LRow

    Test1 = wsRaw.Cells(x, getColumn(wsRaw, "Test1")).Value
    Test2 = wsRaw.Cells(x, getColumn(wsRaw, "Test2")).Value
    Test3 = wsRaw.Cells(x, getColumn(wsRaw, "Test3")).Value


    For col = 3 To 45 Step 2
    If wsRaw.Cells(x, col).Value <> "" Then

    wsAR.Range("L1" & sRow).Value = Test1
    wsAR.Range("L2" & sRow).Value = Test2
    wsAR.Range("L3" & sRow).Value = Test3



    End If



    Next col
    sRow = sRow + 1

    Next x

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Add 5 rows for each row using VBA Macros

    Hi er725Ashok,

    welcome to the Forum. Please note that you should wrap your code in Code-Tags for better readability (highlight the code and hit the #). This is requested in Forum Rule #2.

    May be this code does what you want:

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dynamic rows in macros
    By rpcoates1956 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-16-2016, 04:24 PM
  2. [SOLVED] Two Macros work with 40,000 rows of data but error on 90,000 rows
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2015, 11:47 AM
  3. Replies: 1
    Last Post: 11-28-2013, 05:38 AM
  4. [SOLVED] Macros To Move Multiple Rows To Another Sheet And Macro To Move Single Rows To DAX Table
    By jcaynes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2013, 05:08 PM
  5. I need to insert rows using macros, based on rows values. Please Help!
    By reservoirimgaging in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2013, 02:13 PM
  6. Any way to highlight rows without using macros?
    By Spalding in forum Excel General
    Replies: 2
    Last Post: 11-09-2005, 11:15 AM
  7. Deleting Rows using Macros
    By bernard in forum Excel General
    Replies: 3
    Last Post: 08-08-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1