[2005] Reading Strings from excel sheet (Characterwise) ??
hey guys!
I need to write a code which will read sentences from a specific column in a specified excel sheet.
But I need to store each character in the sentence separately (including space), maybe in an array. I dun rilli know how to go about doing this.
Please Advise
cheers
Abhilash
P.S : I need these characters to be later compared with another excel table to get their dimensions.
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Use the Characters object. Its off of the Range object.
Range.Characters.Count
Range.Characters(Start:=1, Length:=x)
etc.
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Hey RobDog!
I used the Characters Object as you suggested but i am facing a problem. I need to store each character in a range of excel cells separately in an array. I am using a Char array but am getting a InvalidCastException
Conversion from type 'Characters' to type 'Char' is not valid.
the affected code is below.
Code:
For x = 23 To 33 Step 1
n = oSheet1.Range("A" & x).Characters.Count
Dim ActualChar(n - 1) As Char
Dim CharLength(n - 1) As Integer
For y = 0 To n - 1 Step 1
ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1)
The error occurs on the last line of the shown code.
Please advise
Cheers
Abhilash
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Why not define ActualChar as a string Array instead?
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
I tried that also.. it doesnt work.. same error
Code:
Conversion from type 'Characters' to type 'String' is not valid.
I really need to sort this out.. your help will be greatly appreciated..
cheers
Abhilash
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Dim ActualChar(n - 1) As String
ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1).ToString()
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Here is a great tutorial on working with strings in VB: http://www.vbexplorer.com/VBExplorer...tutorial_3.asp
I'd say you can use the split command.
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Hey Rob!
I tried wad u suggested.. it works as in the error doesnt show anymore.. but the value assigned to the variable at the end of the command is some funny statement.
Code:
ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1).ToString()
When i checked the value stored in ActualChar(y) after this statement.. it came out to be something like "System.__ComObject" which is not wads is in the excel sheet.
I Read the tutorial link provided and will try and use some of the commands thr.. it rilli is very useful.. thx mate...
cheers
Abhilash
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
Sorry, didnt verify in the IDE just typed it. The Characters is not a collection but rather an Object. So you may need to CType it to a String type instead.
Re: [2005] Reading Strings from excel sheet (Characterwise) ??
I tried Ctype, but it gives the same problem.. i then tried Mid$ command and it works just fine..
cheers
abhilash