Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 4th, 2003, 10:15 AM
malb4uk malb4uk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 14 malb4uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Read characters in a cell???

I have a column and in this column in each cell there is a name of the file, without the extension. For example: "P570-PT", not includind the quotation marks. What I am trying to do is I want the macro to read all the characters in the cell before dash, and store all this characters ina variable.. Does anybody know how to do that? I greately apreciate your help in advance. Thank you.

Reply With Quote
  #2  
Old September 5th, 2003, 04:04 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
There is two ways to do this. You can get the position of the "-" in the string (with instr) and then grab all the characters of the string before the "-"
e.g.
Code:
Sub Macro1()
Dim sValue As String
Dim iPos As Integer
sValue = Cells(1, 1).Value
iPos = InStr(1, sValue, "-")
If iPos <> 0 Then
    sValue = Mid(sValue, 1, iPos - 1)
    Cells(1, 2).Value = sValue
End If
End Sub

or you can use an array, and split the cell value at the "-" sign
e.g.
Code:
Sub Macro1()
Dim oArrValue
oArrValue = Split(sValue, "-")
Cells(1, 3).Value = oArrValue(0)
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Read characters in a cell???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT