Thread: Help Please
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Help Please

I put the text with similar percentages into the same cell (using alt-enters).

Option Explicit
Sub testme()

Dim curWks As Worksheet
Dim newWks As Worksheet
Dim myRng As Range
Dim myCell As Range
Dim iCol As Long
Dim myVal As Variant
Dim myStr As String

Set curWks = Worksheets("sheet1")
Set newWks = Worksheets.Add

With newWks
With .Range("a1:a100")
.Formula = "=101-row()"
.Value = .Value
End With
End With

With curWks
For iCol = 2 To 6
Set myRng = .Range(.Cells(1, iCol), _
.Cells(.Rows.Count, iCol).End(xlUp))
For Each myCell In myRng.Cells
With myCell
If Trim(.Value) = "" Then
'do nothing
Else
'strip out ###% or _##%
myVal = Trim(Right(.Value, 4))
'remove the % and change it to a value
myVal = CLng(Left(myVal, Len(myVal) - 1))

myStr = newWks.Cells(101 - myVal, iCol).Value
If myStr = "" Then
'do nothing
Else
'add a vblf
myStr = myStr & vbLf
End If
myStr = myStr & Trim(Left(.Value, Len(.Value) - 4))
newWks.Cells(101 - myVal, iCol).Value = myStr
End If
End With
Next myCell
Next iCol
End With

With newWks.UsedRange
.Columns.ColumnWidth = 255
.Columns.AutoFit
.Rows.AutoFit
End With

End Sub


If you put borders around the range,
and on the format|cells|alignment tab
set the vertical alignment to center, it'll look prettier, too.


Himszy wrote:

Hi

I have a table with 7 columns and 100 rows in it. Down the first column
there are the numbers 1-100. The other 6 columns contain (words and then a
percentage next to them) X3. So i have:-

Numbers words1 per.1 words2 per.2 words3 per.3

Now, the percentages belong to the names before them. I need to list the
names next to the large number line but the percentage next to them need to
become the position on the line. If you get me. But also the words in column
words1 can't be mixed up with words2 or 3 , and the same for the other two.

So, if your still with me, which I hope you are, I need a code that can turn
this:-

100 Percentage11 98% Percentage21 95% Percentage31 94%
99 Percentage12 97% Percentage22 91% Percentage32 93%
98 Percentage13 92% Percentage23 95% Percentage33 97%
97 Percentage14 97% Percentage24 97% Percentage34 92%
96
95
94
93
92
........

Into this:-

100
99
98 Percentage11
97 Percentage12 Percentage24 Percentage33
Percentage14
96
95 Percentage21
Percentage23
94
Percentage31
93 Percentage13 Percentage32
92
Percentage34
91 Percentage22

The percentages wont all be in the 90% region but its just an example

Thanks Michael


--

Dave Peterson