Link to home
Start Free TrialLog in
Avatar of gazdzid
gazdzidFlag for United States of America

asked on

Request for explaination - Functions - Loops in VBA

This is in Excel.

The following piece of code works perfect if all I want to do is select every cell on each page 1 at a time.

However if the line below is activated (un-comment) then on the first pass (using F8), it goes right to the biginning of the function. (once hitting the line below)

'Cells(RCI, CCI).Value = Trim(Cells(RCI, CCI).Value)


Code is as follows:

Function Trim()
Worksheets(1).Select
SC = ThisWorkbook.Sheets.Count
SCI = 1
    For SCI = 1 To SC
        Worksheets(SCI).Select
        RC = Range("A1").CurrentRegion.Rows.Count
        cc = Range("A1").CurrentRegion.Columns.Count
            For RCI = 2 To RC     'loops through rows
                For CCI = 1 To cc ' Loops through columns
                    Cells(RCI, CCI).Select
                    'Cells(RCI, CCI).Value = Trim(Cells(RCI, CCI).Value)
                Next CCI
            Next RCI
   Next SCI
End Function
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gazdzid

ASKER

Hey Awesome,

That solved the problem!!

the select was for analysis only.

for visual purposes, I will select the sheets, it gives me some sanity.

Again Thanks!!