?
Solved

Indenting in Excel VBA

Posted on 2013-06-11
2
Medium Priority
?
494 Views
Last Modified: 2013-06-11
Hi all,

I have the following data:

2
2.1
2.1.1
2.1.2
2.2
2.2.1
2.2.2
2.2.3
2.3
2.3.1
2.4
2.5
2.6
2.6.1
2.6.1.1
2.6.1.2
2.6.2
3
3.1
3.1.1
3.1.2

This data is the first column of a list of parent and child items, so item 3.1 belongs to 3 and item 3.1.1 belongs to item 3.1 and so on.

What I would like to do is the following, showing each parent in a separate column:

2      
2.1            2
2.1.1            2.1
2.1.2            2.1
2.2            2
2.2.1            2.2
2.2.2            2.2
2.2.3            2.2
2.3            2
2.3.1            2.3
2.4            2
2.5            2
2.6            2
2.6.1            2.6
2.6.1.1            2.6.1
2.6.1.2            2.6.1
2.6.2            2.6
3
3.1            3
3.1.1            3.1
3.1.2            3.1
etc...

Has anyone got any clever ideas of how to achieve this is Excel VBA?

Thanks in advance
0
Comment
Question by:FMabey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Expert Comment

by:Steve
ID: 39237605
you could use formula:

=LEFT(A2,LEN(A2)-2)
ee.xlsx
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 2000 total points
ID: 39237700
Sub sample()

Dim l As Long, i As Long

i = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(0, 0).Row
l = Len(Range("A2").Value)

For i = 2 To irow
    
    Range("B" & i) = Left(Range("A" & i).Value, l - 2)

Next i

End Sub

Open in new window


Assumption is that all your data is on column A and output will be in column B
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question