|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.
|
|
#2
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Read characters in a cell??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|