Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 13th, 2003, 04:57 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vdriet
Default reading first characters from a cell in excel

Hi, I have a list of Mnemonics of stocks. These lists look like this:

H:AND
H:AH
LX:TRE
W:UIO
etc...

From the letters before the ":" You can determine the country where the stock is trading.

I want to write a simple program that reads the cell where the mnemonic is in and compare the first two characters. If the first two characters are "H:" then I return a "1" in the next column, if "LX" then a "2", if "W:" then a "3" etc... (Dummyvariable)

I would have written the program something like this:



Sub Macro1()

For r = 1 To 20000
    W = Worksheets("Sheet1").Cells(r,2).Value
    If w = "" Then
       GoTo STOPPEN
    End If

    W = W.Substring(0,2)

If W = "H:" Then
   Worksheets("SHeet1").Cells(r,3).Value = 1
End IF

If W = "LX" Then
   Worksheets("SHeet1").Cells(r,3).Value = 2
End IF

If W = "W:" Then
   Worksheets("SHeet1").Cells(r,3).Value = 3
End IF

Next r

STOPPEN:

End Sub



This gives a problem at w = w.Substring(1,2)

Thanks


 
Old August 13th, 2003, 05:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

use
Code:
w = Left(w, 2)
instead.
 
Old August 17th, 2003, 10:10 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vdriet
Default

Thanx

It works excellent






Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying last 8 characters in a cell scandalous Excel VBA 1 December 21st, 2007 11:04 PM
reading from a table cell? Atomsk Access VBA 2 September 28th, 2006 07:46 AM
Reading Values from Excel cell into VB 6 applicati pratlina Beginning VB 6 2 December 28th, 2004 08:28 AM
Parsing special characters from java to excel dracuella J2EE 0 May 19th, 2004 05:14 AM
reading a row of characters from an input file Omega_st1 C++ Programming 4 October 28th, 2003 01:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.