Put data in default format

Fritz1234

New Member
Joined
May 19, 2011
Messages
4
Hey guys,

could you please help me out?

I have a set of data, typically set up like this:

Cell A1: Product name
Cell C1: Price
Cell A2: Description

Cell A3: Product name (#2)
Cell C3: Price (#2)
Cell A4: Description (#2)

.. and so on.

However, some products do not have a description.
In that case, cell A2 (or A4, or A6...) is NOT a blank row but contains the name of the next product.

What I want is to put everything in the above format.
So if a product lacks a description, it should insert a blank row.

The only thing I can think of is to look at column C.
Typically, every second row in C should be empty.
If the second row in C is not empty but contains a price, this means that a blank row should be inserted above (I guess).

I hope this makes any sense, if not please reply, I will try to explain.

Thanks in advance!

 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this on a copy.

1. Right click the sheet and left click "View Code".
2. Paste this:
Code:
Sub fritz1234()
For i = Range("a" & Rows.Count).End(xlUp).Row To 1 Step -1
    If Len(Cells(i, 3)) > 0 And Len(Cells(i + 1, 3)) > 0 Then Rows(i + 1).Insert
Next
End Sub
3. Run
 
Upvote 0
Try this with a copy of your sheet

Code:
Sub Insrows()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    With Range("C" & i)
        If .Value <> "" And .Offset(-1).Value <> "" Then .EntireRow.Insert
    End With
Next i
End Sub
 
Upvote 0
Thanks again guys!

While I'm at it, I ran into a new problem (a smaller one, I guess).

What I want to do is to move every 2nd cell in column A to B-1.

So cell A2 should be moved to B1, A4 to B3, A6 to B5...

The original cells should be left empty, so I can delete blank rows. This I know how to do ;)
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR Step 2
    With Range("A" & i)
        .Cut Destination:=.Offset(-1, 1)
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top