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