Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-14-2013, 12:49 PM
mickeyd mickeyd is offline auto-indent Windows 8 auto-indent Office 2010 64bit
Novice
auto-indent
 
Join Date: Jun 2013
Posts: 1
mickeyd is on a distinguished road
Thumbs down auto-indent

I'm almost a total novice at macros. I have some understanding of the "logic" behind macros, but limited experience.

What I want to do is write a macro where the number in cell A1 will cause the data in B1 to indent based on that number. I assume the macro would go in B1 and look something like: =IF(A1=1)then (B1=0).

Example: if I put the number 1 in A1, I want the data in B1 to stay at 0.
If I put the number 2 in A1, then I want the data in B1 to indent 1 space.



Now comes the tricky part. I want the macro to cover 6 indentations. If A1 =3, then indent 2 spaces. If A1=4, then indent 3 spaces, etc.

Hope that makes sense.

Thanks,
Mickey
Reply With Quote
  #2  
Old 06-14-2013, 04:52 PM
BobBridges's Avatar
BobBridges BobBridges is offline auto-indent Windows 7 64bit auto-indent Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Yeah, I think that can be done, mickeyd. One question: There's an indent feature in Excel; would you rather use that, rather than inserting actual spaces into the data?

If you plan to export the data to some other format, and want the new leading spaces, then you probably have to use actual spaces as you described. But if you want to keep the data in Excel then it may not matter — and if you will be manipulating the data later, and the spaces would mess you up, then it's probably better to use Excel indentation.

To add spaces, the simplest way would be something like this:

' so is the current worksheet.
' jr is the current row.
so.Cells(jr, 2) = Left(" ",so.Cells(jr, 1) - 1) & so.Cells(jr, 2)

That looks at so.Cells(jr, 1) (the indentation value); subtracts 1 from it; cuts a string of spaces down to that many in length; and sticks that in front of the current value of so.Cells(jr, 2).

But if you want to use Excel indentation, it looks more like this:

' so is the current worksheet.
' jr is the current row.
so.Cells(jr, 2).IndentLevel = so.Cells(jr, 1) - 1

Now, if that's enough for you to go on with, go to it. But if you need help writing the actual macro itself, let me know and I'll coach you.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accidental automatic indent? markg2 Word 8 12-10-2012 06:45 PM
auto-indent -right indent?- markbh Word 3 07-16-2012 02:59 PM
Indent Problem adamsoa Word 1 05-07-2012 10:58 PM
auto-indent Indent Problem lkatz1 Word 3 11-16-2011 12:01 AM
Hanging Indent bixby Word 0 07-22-2010 07:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft