LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Code won't run in a subroutine!

Hi folks,
I have some code that works just fine until I place a
portion of it in a subroutine...and then it just doesn't
do squat! Here's the code that works fine:
Dim CellContents As Variant
FinalRow = Cells(65536, 1).End(xlUp).Row
LastColumn = Cells(1, 255).End(xlToLeft).Column - 2
For i = 2 To FinalRow
CellContents = Trim(Cells(i, 2).Value)
Select Case CellContents
Case 9101010 To 9101011
StartColumn = 4
For j = StartColumn To LastColumn Step 1
If IsNumeric(Cells(i, j)) Then
Cells(i, j).Interior.ColorIndex = 40
Cells(i, j).Value = "-" & Cells(i, j).Value
Else
Cells(i, j).Interior.ColorIndex = 35
Cells(i, j).Value = Left(Cells(i, j).Value, Len
(Cells(i, j).Value) - 2)
End If
Next j
Cells(i, 1).Resize(1, 8).Interior.ColorIndex = 4
Case Else
End Select
Next i
End Sub

But...when I pull out the stuff from the middle, and put
this in a subroutine:

StartColumn = 4
For j = StartColumn To LastColumn Step 1
If IsNumeric(Cells(i, j)) Then
Cells(i, j).Interior.ColorIndex = 40
Cells(i, j).Value = "-" & Cells(i, j).Value
Else
Cells(i, j).Interior.ColorIndex = 35
Cells(i, j).Value = Left(Cells(i, j).Value, Len
(Cells(i, j).Value) - 2)
End If
Next j

the program no longer works!
Suggestions???
Thanks,
Craig
 
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
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
SUBROUTINE HELP biker man Excel Discussion (Misc queries) 1 July 28th 07 04:06 PM
Second subroutine to run automatically MatthewT[_7_] Excel Programming 1 January 29th 04 06:59 PM
Code ends subroutine in error Mike[_58_] Excel Programming 3 November 20th 03 12:54 AM
Every second subroutine dolegow Excel Programming 1 October 12th 03 02:11 AM


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