#1   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 60
Default Indentation

How can I indent a cell if another cell contains certain Data.

Example I want to
Indent C1 once if Cell D1 = Detroit
Indent C1 Twice if Cell D1 = Toronto

The sheet may have 400 row.

Any thoughts?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 857
Default Indentation

Hi,

You will need to use code. Here is some sample code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, Range("D1:D400"))
If Not isect Is Nothing Then
'Your code here
End If
End Sub

Record the indent command and then place it into "Your code here

1. To add this code to your file, press Alt+F11,
2. In the VBAProject window, top left side, find your sheet name under your
file name and double click it.
3. Paste in or type the code above.
--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"CB" wrote:

How can I indent a cell if another cell contains certain Data.

Example I want to
Indent C1 once if Cell D1 = Detroit
Indent C1 Twice if Cell D1 = Toronto

The sheet may have 400 row.

Any thoughts?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 857
Default Indentation

Hi,

I only had a few minutes earlier because I was on lunch, but here is your
code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, Range("D1:D100"))
If Not isect Is Nothing Then
If Target = "Detroit" Then ActiveCell.Offset(0, -1).InsertIndent 1
If Target = "Toronto" Then ActiveCell.Offset(0, -1).InsertIndent 2
End If
End Sub


--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"CB" wrote:

How can I indent a cell if another cell contains certain Data.

Example I want to
Indent C1 once if Cell D1 = Detroit
Indent C1 Twice if Cell D1 = Toronto

The sheet may have 400 row.

Any thoughts?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Indentation

without going to VBA
maybe sth like this would prove helpful:

=IF(D1="Detroit",REPT(CHAR(32),5)&B1,IF(D1="Toront o",REPT(CHAR(32),10)&B1,))

presume your data re city in D1 is in B1=252
then if D1 is Detroit this formula inserts 5 spaces before 252
if D1 is Toronto this formula inserts 10 spaces before 252

result of this formula will be text only so if you need to make some
calculations add 0 to them or multpiply them by 1 like here

=IF(D1="Detroit",REPT(CHAR(32),5)&B1,IF(D1="Toront o",REPT(CHAR(32),10)&B1,))*1

pls click YES if this was helpful



Użytkownik "CB" napisał w wiadomo¶ci
...
How can I indent a cell if another cell contains certain Data.

Example I want to
Indent C1 once if Cell D1 = Detroit
Indent C1 Twice if Cell D1 = Toronto

The sheet may have 400 row.

Any thoughts?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Indentation AndrewEdmunds Excel Discussion (Misc queries) 0 October 7th 08 10:20 PM
using vlookup for words w/different indentation HK Excel Worksheet Functions 3 September 15th 06 08:39 PM
Data downloaded with green triangle(indentation) dplatz Excel Worksheet Functions 4 June 16th 06 05:44 PM


All times are GMT +1. The time now is 12:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"