PC Review


Reply
Thread Tools Rate Thread

ActiveCell.Value

 
 
tmarsh7407
Guest
Posts: n/a
 
      26th Apr 2008
I am assigning a two character string to a variable as follows (Stringy is
the variable I read each record form before breaking it into pieces):

ThisActy = Mid(Stringy, 4, 4)

The record I am reading from has "00 " (two zeros and two blanks) starting
at position 4. I then try to insert it into a cell in my spreadsheet as
follows:

ActiveCell.Value = ThisActy

However when I look at the cell I see a 0 (number, not text) in that cell.
I want it to stay in text form in the spreadsheet. What am I doing wrong?
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      26th Apr 2008
Looks like a built in glitch. Here is how I handled it.

Sub jl()
st = Mid(Range("B2"), 4, 4)
st = CStr(st)
Range("A2").NumberFormat = "@"
Range("A2") = st
End Sub

The receiving range has to be formatted as text or it will automatically
convert the "00 " to a number which = 0.

"tmarsh7407" wrote:

> I am assigning a two character string to a variable as follows (Stringy is
> the variable I read each record form before breaking it into pieces):
>
> ThisActy = Mid(Stringy, 4, 4)
>
> The record I am reading from has "00 " (two zeros and two blanks) starting
> at position 4. I then try to insert it into a cell in my spreadsheet as
> follows:
>
> ActiveCell.Value = ThisActy
>
> However when I look at the cell I see a 0 (number, not text) in that cell.
> I want it to stay in text form in the spreadsheet. What am I doing wrong?

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      26th Apr 2008
Have you ever typed
1234_____
( _ = spacebar)
into a cell.

Excel is very forgiving. It'll let you do it, but fix it to be just 1234 (a
real number).

Same thing happens when you plop anything into a cell formatted as General
(non-text).

You could use what JLGWhiz suggested:

with activesheet
.range("a1").numberformat = "@" 'text
.range("A1").value = Mid(stringy, 4, 4)
End With

Or just like you use apostrophes when you're typing something into the cell:

activesheet.range("a1").value = "'" & Mid(stringy, 4, 4)

tmarsh7407 wrote:
>
> I am assigning a two character string to a variable as follows (Stringy is
> the variable I read each record form before breaking it into pieces):
>
> ThisActy = Mid(Stringy, 4, 4)
>
> The record I am reading from has "00 " (two zeros and two blanks) starting
> at position 4. I then try to insert it into a cell in my spreadsheet as
> follows:
>
> ActiveCell.Value = ThisActy
>
> However when I look at the cell I see a 0 (number, not text) in that cell.
> I want it to stay in text form in the spreadsheet. What am I doing wrong?


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last ActiveCell Steven Microsoft Excel Programming 9 18th Sep 2008 02:32 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Microsoft Excel Misc 1 2nd Oct 2007 08:05 PM
How to Revert to ActiveCell.Formula = format from ActiveCell.FormulaR1C1 = format Karthik Bhat - Bangalore Microsoft Excel Programming 1 9th May 2007 02:37 PM
IF ACTIVECELL contains FIRSTROUNDKO via OfficeKB.com Microsoft Excel Programming 4 3rd May 2006 05:17 PM
how to set activecell? ljb Microsoft Excel Programming 2 18th Nov 2003 04:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 PM.