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

sorry hit the wrong button.

I'm pulling a part of a string from one cell, and putting it in another.
I've got the method working, except one problem. In some instances the string
that's being pulled is all numbers. In these cases it's getting put into the
new cell as a date. I've tried applying CStr() to the line, but it still
pulls in the number as a date. How can I go about stopping it from doing
this. Not not all strings getting pulled are numbers, only a handful.

Here's the code I'm using:

lastRow = Cells(Rows.Count, "F").End(xlUp).Row 'Get the last row on the page.

For i = 2 To lastRow 'Start at 2 to ignore heard line.
If Cells(i, "F") < "" Then
Cells(i, "E").Value = Mid(Cells(i, "F"), 1, InStr(1, Cells(i,
"F"), " "))
End If
Next i 'Incriment counter and reloop
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Pulling String

Looks like your target cells are formatted as dates. Change to General.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"RSteph" wrote in message
...
sorry hit the wrong button.

I'm pulling a part of a string from one cell, and putting it in another.
I've got the method working, except one problem. In some instances the

string
that's being pulled is all numbers. In these cases it's getting put into

the
new cell as a date. I've tried applying CStr() to the line, but it still
pulls in the number as a date. How can I go about stopping it from doing
this. Not not all strings getting pulled are numbers, only a handful.

Here's the code I'm using:

lastRow = Cells(Rows.Count, "F").End(xlUp).Row 'Get the last row on the

page.

For i = 2 To lastRow 'Start at 2 to ignore heard line.
If Cells(i, "F") < "" Then
Cells(i, "E").Value = Mid(Cells(i, "F"), 1, InStr(1, Cells(i,
"F"), " "))
End If
Next i 'Incriment counter and reloop



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Pulling String

How can I apply the General or text format to the cell in VBA? I know how to
do it on the excel spreadsheet by formatting the cell, but I'm creating the
column just before I run this loop. So I'd have to format it then.

"Bob Phillips" wrote:

Looks like your target cells are formatted as dates. Change to General.

--
HTH

Bob Phillips

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Pulling String

columns("G").numberformat="General"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"RSteph" wrote in message
...
How can I apply the General or text format to the cell in VBA? I know how

to
do it on the excel spreadsheet by formatting the cell, but I'm creating

the
column just before I run this loop. So I'd have to format it then.

"Bob Phillips" wrote:

Looks like your target cells are formatted as dates. Change to General.

--
HTH

Bob Phillips



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Pulling String

Change your If statement to add a line as follows:
If Cells(i, "F") < "" Then
Cells(i,"E").NumberFormat = "General"
Cells(i, "E").Value = Mid(Cells(i, "F"), _
1, InStr(1, Cells(i, "F"), " "))
End If

That will make sure the format is the same for each cell you post to.


"RSteph" wrote:

sorry hit the wrong button.

I'm pulling a part of a string from one cell, and putting it in another.
I've got the method working, except one problem. In some instances the string
that's being pulled is all numbers. In these cases it's getting put into the
new cell as a date. I've tried applying CStr() to the line, but it still
pulls in the number as a date. How can I go about stopping it from doing
this. Not not all strings getting pulled are numbers, only a handful.

Here's the code I'm using:

lastRow = Cells(Rows.Count, "F").End(xlUp).Row 'Get the last row on the page.

For i = 2 To lastRow 'Start at 2 to ignore heard line.
If Cells(i, "F") < "" Then
Cells(i, "E").Value = Mid(Cells(i, "F"), 1, InStr(1, Cells(i,
"F"), " "))
End If
Next i 'Incriment counter and reloop



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
Pulling Year from a text string Elkar Excel Worksheet Functions 0 February 20th 07 06:33 PM
Pulling string RSteph Excel Programming 0 October 31st 06 05:48 PM
Pulling apart a string Kevin O'Neill[_2_] Excel Programming 6 January 6th 06 05:30 PM
URL string, pulling in Stock Data William Benson[_2_] Excel Programming 0 July 15th 05 05:08 AM
pulling characters out of a string Patrick Excel Worksheet Functions 3 November 12th 04 06:58 PM


All times are GMT +1. The time now is 04:27 AM.

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"