Solved

Indenting in Excel VBA

Posted on 2013-06-11
2
491 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 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

730 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