Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



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
Malfunction formulae Yvonne Excel Discussion (Misc queries) 1 October 30th 09 07:06 PM
Help Excel malfunction mingster Excel Discussion (Misc queries) 9 July 21st 06 09:46 PM
pPMT malfunction Louis Zaffino Excel Worksheet Functions 1 May 3rd 06 07:13 PM
AutoSum malfunction DUFFBEER Charts and Charting in Excel 2 April 27th 06 03:06 PM
Code malfunction Phil Hageman[_3_] Excel Programming 4 December 20th 03 03:54 PM


All times are GMT +1. The time now is 06:03 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"