Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default ByRef question

What's wrong with this code? I'm getting a ByRef type mismatch error.

Sub SetRange()
Dim topCel As Range, bottomCel As Range
Set topCel = ActiveCell
If IsEmpty(topCel) Then Set topCel = topCel.End(xlDown)
Set bottomCel = Cells(65536, topCel.Column).End(xlUp)
If bottomCel.Row < topCel.Row Then Set topCel = bottomCel
Set myRng = Range(topCel, bottomCel)
myRng.NumberFormat = "@"
Call FormatCells(myRng)
End Sub


Sub FormatCells(ByRef myRng As Range)
For Each cel In myRng
If cel.Value < 1000 Then
cel.Value = "0" & Left(cel, 1) & ":00"
Else
cel.Value = Left(cel, 2) & ":00"
End If
Next
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default ByRef question

Tommy,

Declare the myRng variable as a range. E.g.,
Dim myRng As Range


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tommy Flynn" wrote in message
...
What's wrong with this code? I'm getting a ByRef type mismatch error.

Sub SetRange()
Dim topCel As Range, bottomCel As Range
Set topCel = ActiveCell
If IsEmpty(topCel) Then Set topCel = topCel.End(xlDown)
Set bottomCel = Cells(65536, topCel.Column).End(xlUp)
If bottomCel.Row < topCel.Row Then Set topCel = bottomCel
Set myRng = Range(topCel, bottomCel)
myRng.NumberFormat = "@"
Call FormatCells(myRng)
End Sub


Sub FormatCells(ByRef myRng As Range)
For Each cel In myRng
If cel.Value < 1000 Then
cel.Value = "0" & Left(cel, 1) & ":00"
Else
cel.Value = Left(cel, 2) & ":00"
End If
Next
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default ByRef question

Thanks, that did the trick.

Tommy


"Chip Pearson" wrote in message
...
Tommy,

Declare the myRng variable as a range. E.g.,
Dim myRng As Range


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tommy Flynn" wrote in message
...
What's wrong with this code? I'm getting a ByRef type mismatch error.

Sub SetRange()
Dim topCel As Range, bottomCel As Range
Set topCel = ActiveCell
If IsEmpty(topCel) Then Set topCel = topCel.End(xlDown)
Set bottomCel = Cells(65536, topCel.Column).End(xlUp)
If bottomCel.Row < topCel.Row Then Set topCel = bottomCel
Set myRng = Range(topCel, bottomCel)
myRng.NumberFormat = "@"
Call FormatCells(myRng)
End Sub


Sub FormatCells(ByRef myRng As Range)
For Each cel In myRng
If cel.Value < 1000 Then
cel.Value = "0" & Left(cel, 1) & ":00"
Else
cel.Value = Left(cel, 2) & ":00"
End If
Next
End Sub






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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
where can I see my question and answer? Yesterday I ask a question IP Excel Discussion (Misc queries) 2 May 10th 08 04:08 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
ByRef not passing address Ian Stanborough Excel Programming 3 October 30th 03 01:30 PM
Is ByVal always better if ByRef isn't necessary Jeff[_17_] Excel Programming 5 July 25th 03 09:25 AM


All times are GMT +1. The time now is 07:45 PM.

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

About Us

"It's about Microsoft Excel"