How to automatically insert a copied row after a specific value in a cell with VBA

How to automatically insert a copied row after a specific value in a cell with VBA

I have a table that contains a set of bundles that have to be broken down into their components. For this I'm looking for VBA instructions that will copy any row that contains the tag "-edubnd" at the end of the 'sku' cell (please see table bellow for example) twice underneath itself.

I have a table that contains a set of bundles that have to be broken down into their components. For this I'm looking for VBA instructions that will copy any row that contains the tag "-edubnd" at the end of the 'sku' cell (please see table bellow for example) twice underneath itself.

It might be easier to ignore the tag component and use a specific set of values that the code looks for, that's also possible as the values marked as bundles are always the same in the column. What I mean is, instead of looking for the -edubnd tag, the code just looks for a specific value in that column,

I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question.

I'm currently filtering out the dataset, copying it into a different excel document, then running this:

Sub insertrows()

Dim I As Long

Dim xCount As Integer

LableNumber:

xCount = 2

For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 1 Step -1

Rows(I).Copy

Rows(I).Resize(xCount).Insert

Next

Application.CutCopyMode = False

End Sub

_

CURRENT TABLE:

column1   |    column2    |  column3 |  column3
----------------------------------------------
  A       |      pear     |  blue    |  10
  A       |      apple    |  orange  |  50
  A       |      orange   |  yellow  |  30
  A       |      kiwi     |  yellow  |  20
  A       | orange-edubnd |  blue    |  100
  A       |      apple    |  green   |  10
  A       |  pear-edubnd  |  green   |  50
  A       |      mango    |  pink    |  60

_

DESIRED TABLE

Note: the copied row after each distinct column2 with the -edubnd tag

 column1   |    column2    |  column3 |  column3
----------------------------------------------
  A       |      pear     |  blue    |  10
  A       |      apple    |  orange  |  50
  A       |      orange   |  yellow  |  30
  A       |      kiwi     |  yellow  |  20
  A       | orange-edubnd |  blue    |  100
  A       | orange-edubnd |  blue    |  100
  A       | orange-edubnd |  blue    |  100
  A       |      apple    |  green   |  10
  A       |  pear-edubnd  |  green   |  50
  A       |  pear-edubnd  |  green   |  50
  A       |  pear-edubnd  |  green   |  50
  A       |      mango    |  pink    |  60


excel-vba excel

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Excel VBA Tutorial for Beginners 17- Delete Cells using VBA in MS Excel

In this MS Excel VBA video, we are going to see that how can we delete cells in excel using the VB code in the VBA editor and the Overview of formulas in Excel. We will see Basic Excel formulas & functions with examples .

Excel VBA Tutorial for Beginners 16 - Clear Cells in Excel using VBA

In thi MS Excel VBA video, we are going to look at how can we use the VB code to clear up cells in MS Excel. The clear cells feature of MS Excel is used for the purpose. Using this feature we can easily clear cell contents, cell formatting, cell comments and hyperlinks as well

Excel VBA Tutorial for Beginners 20 - Column Width Manipulation in Excel VBA

In this MS Excel VBA video, we are going to see how can we use the VB code to manipulate the Column Width of Cells in MS Excel. So we are going to use two methods and explore them in detail, along with this we aare also going to see that what are the possible values for the width of columns

Excel VBA Tutorial for Beginners 10 - Background Colors in Excel VBA

In this Excel VBA video, we are going to see the usage of With Block in Excel VBA. Using with block, we can reuse and rewrite multiple code lines. Also we are going to look at the interior property in brief as well, which allows us to set background colors and background gradient as well

Excel VBA Tutorial for Beginners 11 - Excel VBA PasteSpecial Method

In this Excel VBA video, we are going to look at the usage of the Paste Special function in Excel using the VB code. Paste Special function helps us to use the paste function in different formats such as Pasting Cell Width, Pasting Text only, Pasting Cell Formats.