I have this code that paste data from an excel sheet to my MSHFlexgrid1.
I would like to TRIM each text in MSHFlexgrid cell when data is in it.
How can i do this?
Thanks again for your help
Full code
Dim ARRAYLINES As Variant ' array with the lines Dim ARRAYCELLS As Variant ' array with the cells of 1 line to count the cols needed Dim ARRAYLINESidx As Integer '§ put clipboard in textbox With Text2 .Text = Clipboard.GetText If .Text = "" Then MsgBox "No data in clipboard" Exit Sub Else ARRAYLINES = Split(.Text, vbNewLine) End If End With '§ put textbox in grid If ARRAYLINES(0) = "" Then MsgBox "No data" Exit Sub Else ARRAYCELLS = Split(ARRAYLINES(0), vbTab) With MSHFlexGrid1 .Cols = UBound(ARRAYCELLS) + 1 .Rows = 0 '§ keep header For ARRAYLINESidx = LBound(ARRAYLINES) To UBound(ARRAYLINES) - 1 .AddItem (ARRAYLINES(ARRAYLINESidx)) Next End With End If '§ clear array ReDim ARRAYLINES(0) ReDim ARRAYCELLS(0)
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Martin Liss
All you have in that cell is "wer" with spaces before and after it so Trim should work just fine. What do you see after you trim it?
Wilder1626
ASKER
i still see the spaces in the cell.
I did 2 row, one with spaces in the "WER" and one with no spaces.
ARRAYCELLS = Split(ARRAYLINES(0), vbTab) With MSHFlexGrid1 .Cols = UBound(ARRAYCELLS) + 1 .Rows = 0 '§ keep header For ARRAYLINESidx = LBound(ARRAYLINES) To UBound(ARRAYLINES) - 1 '.AddItem (ARRAYLINES(ARRAYLINESidx)) .AddItem (Trim(ARRAYLINES(ARRAYLINESidx))) Next End With End If '§ clear array ReDim ARRAYLINES(0) ReDim ARRAYCELLS(0)
Unlimited question asking, solutions, articles and more.
Martin Liss
Are you saying that you see spaces in line 2? If so where?
Also (and this isn't the problem), you definitely don't need the outside parentheses around Trim. And unless there's code after line 30 where you want to reuse the two arrays, there's no need to Redim them since VB6 will initialize them the next time the code is run.
One thing to try.
Dim ARRAYLINES() As String
Dim ARRAYCELLS() As String
Wilder1626
ASKER
thanks again for your help.
What i did it to trafer the row in multiple text box and all textbox are trim
Thanks again
Wilder1626
ASKER
I tried by updating:
Dim ARRAYLINES() As String
Dim ARRAYCELLS() As String
But still same result.
I have also deleted:
'§ clear array
ReDim ARRAYLINES(0)
ReDim ARRAYCELLS(0)
And also updated:
.AddItem Trim(ARRAYLINES(ARRAYLINESidx))
Your help has saved me hundreds of hours of internet surfing.
fblack61
Martin Liss
What was the problem?
Wilder1626
ASKER
well there is no error but it's just does not trim the text once in the grid.
Wilder1626
ASKER
After a good night of sleep, i decided to do it the easy way. Probably not the best way.
I put the code bellow after uploading the data in my MSHFlexgrid.
Dim lngRow As LongDim lngCol As LongFor lngRow = 0 To MSHFlexGrid1.Rows - 1 For lngCol = 0 To MSHFlexGrid1.Cols - 1 MSHFlexGrid1.TextMatrix(lngRow, lngCol) = Trim(MSHFlexGrid1.TextMatrix(lngRow, lngCol)) NextNext
I did try both option but still, it does not trim each cell.
.AddItem Trim(ARRAYLINES(ARRAYLINES
.AddItem (Trim(ARRAYLINES(ARRAYLINE