PDA

View Full Version : Solved: Setting Array for Two Sheets- Almost there



YellowLabPro
09-14-2007, 07:26 AM
I want to run the trim function on two sheets.
The following code does not make it to the second sheet, it gets to the next Ai, "ArrayInteger", but that does not tell it to perform the trim on the second sheet, rather it starts over again and runs on the first sheet.

My variable counters are also a problem, they contain the value of the last variable count, "which is to be expected". What is the best way to reset them, place another "i = 4" after the Next i, and place this line a second time after "Next j"-
lrwSource = .Cells(Rows.Count, 1).End(xlUp).Row

Sub RemoveSpaces()
Dim Ws As Worksheet
Dim i As Integer, j As Integer, lrwSource As Long, Ai As Long
Dim ArrayWs
ArrayWs = Array("TGFF", "TGVB")
Set Ws = Worksheets(ArrayWs(Ai))
With Ws
For Ai = LBound(ArrayWs) To UBound(ArrayWs)
lrwSource = .Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To 4
For i = 4 To lrwSource
.Cells(i, j).Value = WorksheetFunction.Trim(.Cells(i, j).Value)
Next i
Next j
Next Ai
End With
MsgBox "Done"
End Sub

rory
09-14-2007, 07:32 AM
You're not changing ws - try:

Sub RemoveSpaces()
Dim Ws As Worksheet
Dim i As Integer, j As Integer, lrwSource As Long, Ai As Long
Dim ArrayWs
ArrayWs = Array("TGFF", "TGVB")
For Ai = LBound(ArrayWs) To UBound(ArrayWs)
Set Ws = Worksheets(ArrayWs(Ai))
With Ws
lrwSource = .Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To 4
For i = 4 To lrwSource
.Cells(i, j).Value = WorksheetFunction.Trim(.Cells(i, j).Value)
Next i
Next j
End With
Next Ai
MsgBox "Done"
End Sub

YellowLabPro
09-14-2007, 07:49 AM
Thanks Dude!
I see it now..... hindsight 20/20
It would be better though if you guys would get me a copy of the VBA that runs that special code, the ones w/ the .cells(iwish1, iwish2).value

rory
09-14-2007, 07:59 AM
You just need a copy of Office Super Professional Pro Plus Ultimate Teachers Edition, which has all the answers...

YellowLabPro
09-14-2007, 08:05 AM
I knew you guys were holding out on me. Okay, I'll bite, where do I get this and how much..... HogWarts School probably- Huh?... Only problem.... I still have the status of a Muggle

rory
09-14-2007, 08:24 AM
From the Microsoft shop of course...

YellowLabPro
09-14-2007, 08:26 AM
So all I have to do is call them up and they will know what I am talking about and I can get one... what's the catch?

rory
09-14-2007, 08:31 AM
It's online only. All you have to do is log in with the secret password and away you go. :)

YellowLabPro
09-14-2007, 09:56 AM
Sounds to me like you might be pulling my leg on this one.... I have searched for this password for hours... and nothing