![]() |
Function - Malfunction
What is my error? in the following piece of code? Format_Cells(A) is a function; A is a Range Object. I'm trying to call the function Function Format_Cells(A As Range) in my main code with error 424 --------------------------------------------------------------- Main Program --------------------------------------------------------------- Dim A as Range Range("Y11:BR41").Select Set A = Worksheets("Summary").Range("Y11:BR41") Format_Cells (A) --------------------------------------------------------------- Function --------------------------------------------------------------- Function Format_Cells(A As Range) With Selection.Borders(xlEdgeLeft) ..LineStyle = xlContinuous ..Weight = xlThin ..ColorIndex = 16 End With With Selection.Borders(xlEdgeTop) ..LineStyle = xlContinuous ..Weight = xlThin ..ColorIndex = 16 End With With Selection.Borders(xlEdgeBottom) ..LineStyle = xlContinuous ..Weight = xlThin ..ColorIndex = 2 End With With Selection.Borders(xlEdgeRight) ..LineStyle = xlContinuous ..Weight = xlThin ..ColorIndex = 2 End With With Selection.Borders(xlInsideVertical) ..LineStyle = xlContinuous ..Weight = xlHairline ..ColorIndex = 16 End With With Selection.Borders(xlInsideHorizontal) ..LineStyle = xlContinuous ..Weight = xlHairline ..ColorIndex = 16 End With With Selection.Interior ..ColorIndex = 19 ..Pattern = xlSolid ..PatternColorIndex = xlAutomatic End With With Selection.Font ..Name = "Tahoma" ..FontStyle = "Regular" ..Size = 8 ..ColorIndex = xlAutomatic End With End Function ---------------------------------------------------------------- -- Baapi ------------------------------------------------------------------------ Baapi's Profile: http://www.excelforum.com/member.php...o&userid=27333 View this thread: http://www.excelforum.com/showthread...hreadid=469377 |
Function - Malfunction
Your function doesn't return anything, so change it to a sub instead.
Your "with" syntax is wrong - check docs. You pass a range to the code but do not use it in the routine Try something like: Sub FormatCells(rng as range) With rng.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 16 End With 'etc etc End Sub Call like this FormatCells Worksheets("Summary").Range("Y11:BR41") -- Tim Williams Palo Alto, CA "Baapi" wrote in message ... What is my error? in the following piece of code? Format_Cells(A) is a function; A is a Range Object. I'm trying to call the function Function Format_Cells(A As Range) in my main code with error 424 --------------------------------------------------------------- Main Program --------------------------------------------------------------- Dim A as Range Range("Y11:BR41").Select Set A = Worksheets("Summary").Range("Y11:BR41") Format_Cells (A) --------------------------------------------------------------- Function --------------------------------------------------------------- Function Format_Cells(A As Range) With Selection.Borders(xlEdgeLeft) LineStyle = xlContinuous Weight = xlThin ColorIndex = 16 End With With Selection.Borders(xlEdgeTop) LineStyle = xlContinuous Weight = xlThin ColorIndex = 16 End With With Selection.Borders(xlEdgeBottom) LineStyle = xlContinuous Weight = xlThin ColorIndex = 2 End With With Selection.Borders(xlEdgeRight) LineStyle = xlContinuous Weight = xlThin ColorIndex = 2 End With With Selection.Borders(xlInsideVertical) LineStyle = xlContinuous Weight = xlHairline ColorIndex = 16 End With With Selection.Borders(xlInsideHorizontal) LineStyle = xlContinuous Weight = xlHairline ColorIndex = 16 End With With Selection.Interior ColorIndex = 19 Pattern = xlSolid PatternColorIndex = xlAutomatic End With With Selection.Font Name = "Tahoma" FontStyle = "Regular" Size = 8 ColorIndex = xlAutomatic End With End Function ---------------------------------------------------------------- -- Baapi ------------------------------------------------------------------------ Baapi's Profile: http://www.excelforum.com/member.php...o&userid=27333 View this thread: http://www.excelforum.com/showthread...hreadid=469377 |
All times are GMT +1. The time now is 01:50 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com