Seeking method to indent if first character in cell is not a number

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
Using Excel 2010, column C includes values, some of which start with a number and others which start with a letter. Like this:

Code:
1) Footnote
2) Footnote2
a) sub footnote
b) sub footnote 2
3) Footnote3
a) sub foonote

I am seeking a method to indent the sub footnotes, the cells which do not start with a number. The end result should look like this:

Code:
1) Footnote
2) Footnote2
   a) sub footnote
   b) sub footnote 2
3) Footnote3
   a) subfootnote

I have this bit of code which looks for the word 'No', then indents the adjacent cell. I don't need the offset part, but I'd like to adapt it to do what is shown above based on if the first character is not a number.

Code:
For Each i in Sheets("Output").Range("C2:C100")  
        If i.Value = "No" Then
        i.Offset(0,1).InsertIndent 2
    End If
Next i

Just can't wrap my head around how to do this. Would appreciate any thoughts.

Thanks

Jim
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
Code:
For i = 2 To 10
   If IsNumeric(Left(Range("A" & i), 1)) Then
      Range("A" & i).InsertIndent 2
   End If
Next i
 
Upvote 0
Works like a charm.... Thanks for your prompt reply!

Jim
 
Upvote 0
Actually, I made a small change, since I want to indent if the first character is NOT a number. Posting a reply for others who may search and find this topic....

Code:
For i = 2 To 21
   If IsNumeric(Left(Range("C" & i), 1)) Then
      GoTo x
      Else
      Range("C" & i).InsertIndent 2
   End If
x:
Next i
 
Upvote 0
You can also do what you want without using a loop... this single line of code should also do what you asked for.
Code:
[table="width: 500"]
[tr]
	[td][Output!C2:C100].IndentLevel = [IF(ISNUMBER(-LEFT(Output!C2:C100)),0,2)][/td]
[/tr]
[/table]
 
Upvote 0
Alternatively
Code:
For i = 2 To 10
   If [COLOR=#ff0000]Not [/COLOR]IsNumeric(Left(Range("A" & i), 1)) Then
      Range("A" & i).InsertIndent 2
   End If
Next i
 
Upvote 0
One last questions>>>> when will I be as smart as the two of you?
 
Upvote 0
One last questions>>>> when will I be as smart as the two of you?
Smart may not be an appropriate word to describe me (just ask my wife :LOL:)... what I know about VBA comes from years and years of programming experience, first in several variants of BASIC (the predecessor to the compiled version of VB), then the compiled version of Visual Basic (the predecessor to VBA) and finally VBA (there were a few other languages I programmed in across the years as well). I learned my first variant of BASIC back in 1981 and have written code in BASIC/VB/VBA literally every day since. After more than 35 years of programming, you kind of develop certain coding techniques which tend to come to you automatically when you see coding problems that need to be solved. I am not sure where you are along the programming skill curve, but my advice is to read the problems posed here in this forum and read the various solutions offered, more importantly try to figure out how and why the code works... you cannot have a better teacher than working out, on your own, why and how certain pieces of code work. Even after many years of programming experience, I learned a tremendous amount of new techniques when I first started volunteering answering question in various Excel forums (mostly the MrExcel formum). If you are stuck in figuring it out, ask the poster of the code if they can explain whatever code line is giving you trouble that you are trying to figure out... the volunteers here are usually nice enough to help out that way (assuming their time commitments allow them the time to do so).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,986
Messages
6,128,115
Members
449,423
Latest member
Mike_AL

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