Indians1022
New Member
- Joined
- Aug 15, 2018
- Messages
- 7
Hello,
I am having some trouble with figuring out how to insert blank rows to my data set. I have been able to find information and figure out how to insert blank rows based off of one column. The problem for me is that I need to be able to do this for multiple columns where the data value changes. I've tried several different code combinations, but I have not been successful with combining them into one single macro yet. I have shared a sample of my data and the result that I am trying to achieve.
Data Set: Data Set starts in cell "A2"
Result Needed:
So far my code looks like this:
I am still pretty new to VBA, so this is all still a learning process for me. With my code that I shared above I have been able to add rows based off of Column A and put the correct values in the newly inserted rows, but then I have been running into trouble with trying to do this to Columns B & C.
I have a feeling that I am coding the macro wrong due to my lack of experience with VBA and that it probably isn't as difficult as I am making it seem. If anyone has any pointers or ideas to help nudge me in the right direction, I would greatly appreciate it. Thank you in advance!
Have a wonderful day, God Bless!
- Indians1022
I am having some trouble with figuring out how to insert blank rows to my data set. I have been able to find information and figure out how to insert blank rows based off of one column. The problem for me is that I need to be able to do this for multiple columns where the data value changes. I've tried several different code combinations, but I have not been successful with combining them into one single macro yet. I have shared a sample of my data and the result that I am trying to achieve.
Data Set: Data Set starts in cell "A2"
Code:
[TABLE="width: 774"]
<tbody>[TR]
[TD]AUTOMOTIVE[/TD]
[TD] GENERAL AUTOMOTIVE[/TD]
[TD] TUNE UP EQUIPMENT[/TD]
[TD] TESTERS & METERS[/TD]
[/TR]
[TR]
[TD]AUTOMOTIVE[/TD]
[TD] GENERAL AUTOMOTIVE[/TD]
[TD] WHEEL & JACKEQUIPMENT[/TD]
[TD] AIR PUMPS[/TD]
[/TR]
[TR]
[TD]AUTOMOTIVE[/TD]
[TD] GENERAL AUTOMOTIVE[/TD]
[TD] WHEEL & JACKEQUIPMENT[/TD]
[TD] JACKS[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 774"]
<tbody>[TR]
[TD]AUTOMOTIVE[/TD]
[TD] GENERAL AUTOMOTIVE[/TD]
[TD] WIPER BLADES[/TD]
[TD] WIPER BLADES SETS[/TD]
[/TR]
[TR]
[TD]AUTOMOTIVE[/TD]
[TD] RV & MOBILEHOME SUPPLIES[/TD]
[TD] MOBILE HOME SUPPLIES[/TD]
[TD] MOBILE HOME ELECTRICAL[/TD]
[/TR]
</tbody>[/TABLE]
Code:
AUTOMOTIVE
AUTOMOTIVE GENERAL AUTOMOTIVE
AUTOMOTIVE GENERAL AUTOMOTIVE TUNE UP EQUIPMENT
AUTOMOTIVE GENERAL AUTOMOTIVE TUNE UP EQUIPMENT TESTERS & METERS
AUTOMOTIVE GENERAL AUTOMOTIVE WHEEL & JACK EQUIP.
AUTOMOTIVE GENERAL AUTOMOTIVE WHEEL & JACK EQUIP. AIR PUMPS
AUTOMOTIVE GENERAL AUTOMOTIVE WHEEL & JACK EQUIP. JACKS
AUTOMOTIVE GENERAL AUTOMOTIVE WIPER BLADES
AUTOMOTIVE GENERAL AUTOMOTIVE WIPER BLADES WIPER BLADE SETS
AUTOMOTIVE
AUTOMOTIVE RV & MOBILEHOME SUPPLIES
AUTOMOTIVE RV & MOBILEHOME SUPPLIES MOBILE HOME SUPPLIES
AUTOMOTIVE RV & MOBILEHOME SUPPLIES MOBILE HOME SUPPLIES MOBILE HOME ELECTRICAL
AUTOMOTIVE RV & MOBILEHOME SUPPLIES MOBILE HOME SUPPLIES MOBILE HOME HARDWARE
So far my code looks like this:
Code:
Sub AddRows()
Dim aRow As Integer
Dim aCol As Integer
Dim aRange As Range
Set aRange = Range("A1")
aRow = aRange.Row
aCol = aRange.Column
Do
If Cells(aRow + 1, aCol) <> Cells(aRow, aCol) Then
Cells(aRow + 1, aCol).EntireRow.Resize(3).Insert shift:=xlDown
Cells(aRow + 1, aCol) = Cells(aRow + 4, aCol)
Cells(aRow + 2, aCol) = Cells(aRow + 4, aCol)
Cells(aRow + 3, aCol) = Cells(aRow + 4, aCol)
Cells(aRow + 4, aCol) = Cells(aRow + 4, aCol)
Cells(aRow + 2, 2) = Cells(aRow + 4, 2)
Cells(aRow + 3, 2) = Cells(aRow + 4, 2)
Cells(aRow + 3, 3) = Cells(aRow + 4, 3)
aRow = aRow + 5
Else
aRow = aRow + 1
End If
Loop While Not Cells(aRow, aCol).Text = ""
End Sub
I am still pretty new to VBA, so this is all still a learning process for me. With my code that I shared above I have been able to add rows based off of Column A and put the correct values in the newly inserted rows, but then I have been running into trouble with trying to do this to Columns B & C.
I have a feeling that I am coding the macro wrong due to my lack of experience with VBA and that it probably isn't as difficult as I am making it seem. If anyone has any pointers or ideas to help nudge me in the right direction, I would greatly appreciate it. Thank you in advance!
Have a wonderful day, God Bless!
- Indians1022