Microsoft
Software
Hardware
Network
Question : Putting functions in a VBA Macro in Excel or indenting as a macro.
Morning,
I'm trying to create a VBA Macro in Excel that indents the contents of a cell based upon the value of the cell next to it and then runs down a column doing the same for each pair of cells.
Example:
Cell A1 = 3, Cell B1 needs to be indented 3 spaces.
Cell A2 =1, Cell B2 needs to be indented 1 space.
I'm stuck trying to work out how to put an =Cell function within a Macro and unfortunately for me, I'm a complete novice at VBA.
Range("B1").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = ( EQUALS FUNCTION HERE)
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Is this even possible, or is there a better way to do what I'm after?
Many Thanks
Will
Answer : Putting functions in a VBA Macro in Excel or indenting as a macro.
Range("B1").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = Range("A1").Value
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
or if you want to do lots of cells:
For Each rngCell in Selection
With rngCell
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = .Offset(0,-1).Value
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Next rngCell
just select the cells in column B before running the macro.
HTH
Rory
Random Solutions
USB Falsh Drive keeps asking for Drivers
Date conversion
Microsoft SSIS Service failed to start. Error: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
vb.net selected item from listview
Display No Rows or No Data Found Message for the Matrix in SSRS
Page life expectancy
OK to remove "Windows\TEMP ?
Regional settings GREEK , decimal separator "," sql server 2000, But does not update a textbox tha binds to a float field,C# framework 2.0
Find a Text in a cell and copy it to another cell.
Access 2003: shell command - quest 2