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: 1
Default Casting Problem in VBA

See code below. I load the departments collection with string values
(For example 007). When I print out the values in a message box they
are string values (For example 007). But when I execute the statement:
Sheets("Expenses").Range("E3") = CStr(departments(i))
.... the value that gets put into the spreadsheet is NUMERIC (For
example 7). I added the CStr cast to String, but that did not help.
What must I do to update E3 with a String instead of a Numeric?

Thanks,

Russ


Dim departments As New Collection
Dim sitem As String

'Make sure the right worksheet is active
Worksheets("Legend").Activate

' Load all of the Codes in departments collection
' Start at top of list and continue until you hit a blank cell
Sheets("Legend").Range("B3").Select
Do While IsEmpty(ActiveCell.Offset(0, 1)) = False
sitem = ActiveCell.Value
departments.Add (sitem)
ActiveCell.Offset(1, 0).Select
Loop

' TEMPORARY - output the collection count
MsgBox departments.Count

' TEMPORARY - List the contents of the collection.
For i = 1 To departments.Count
MsgBox departments(i)
Next

'Loop through all departments, filling in the department number
' on the Expenses sheet. Recalculate spreadsheet and print.
For i = 1 To departments.Count
Sheets("Expenses").Range("E3") = CStr(departments(i))
Calculate
With Worksheets("Sheet1").PageSetup
.CenterHorizontally = True
.PrintArea = "$A$1:$T$39"
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'Worksheets("Expenses").PrintOut
Next

 
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
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
Changing text to number format using type casting Tomski[_15_] Excel Programming 3 January 19th 06 02:48 PM
Casting in an Excel ADO SQL Command Developer of the Caribbean Excel Programming 4 September 1st 05 05:31 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


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