ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Indentation (https://www.excelbanter.com/excel-discussion-misc-queries/223800-indentation.html)

CB

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?

Shane Devenshire

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?


Shane Devenshire

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?


Jarek Kujawa[_3_]

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?





All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com