Link to home
Start Free TrialLog in
Avatar of Patmurf
Patmurf

asked on

perform action then move and repeat specified number of times

I need to resize columns 36 times. Basically, I start at column "F", set width to 10.43, move position 3 columns to right and repeat action 35 more times and then stop.
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Try

Sub set3rdcolwidth()
Dim i as long
For i = 6 To 42 Step 3
    Cells(1, i).EntireColumn.ColumnWidth = 10.43
Next i
End Sub
Avatar of Patmurf
Patmurf

ASKER

It appears to set the column width for the target column, but it doesn't move 3 columns to the right and repeat. It does stop after a number of iterations.

I observed the action in na step-through view.
SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

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 Patmurf

ASKER

It sort of works. It does march through the columns and makes the width proper, however, the first action is to go to cell (1,1) when I would hope it would stay where I want it to start - in cell (1,8) - and progress from there on for the 120 iterations.

The code slightly changed is as follows:

Option Explicit
Sub set3rdcolwidth()
Dim i As Long
For i = 1 To 120 Step 3
    Cells(1, i).EntireColumn.Select
    Cells(1, i).EntireColumn.ColumnWidth = 10.43
Next i
End Sub
Avatar of Patmurf

ASKER

If you are still there, any idea how to hold the cursor at a particular position (column H) and have movement relative to that position and not return to cell A:1?
Sorry I missed your previous post.

I do not understand what you are trying to achieve in your last post.

hold the cursor....have movement....not return
Avatar of Patmurf

ASKER

Oh, sorry.
I have the cursor at the top of column "G" and want to set the column width to 10.43.  My wish is then to move 3 columns to the right (column "J") and set that column width to 10.43.

I then need to continue this movement and setting column width until I get to column "DH" at which point the code should stop. That is 57 moves in which every 3rd column starting with column "G" has it's width set. All intervening cells have nothing done to them.

I hope this is clearer. If you wish to make this easier, I can send the SS since there is nothing confidential.
The difference between this and my last code is that it will select the first cell of every third column instead of every third entire column. Is this what you want?

Sub set3rdcolwidth()
Dim i As Long
For i = 1 To 120 Step 3
    Cells(1, i).Select
    Cells(1, i).EntireColumn.ColumnWidth = 10.43
Next i
End Sub
SOLUTION
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 Patmurf

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for Patmurf's comment #a40012350

for the following reason:

Ultimately, I needed to understand the coding provided by the expert, discover where the code was not doing what I wanted and made the fix myself.

However, without the expert, I was clueless as to how to start. The expert DID provide the framework for me to understand the code that was needed and that I had to understand a little more than I previously had to be able to make my own changes to make the code work as I wanted. I view this experience as a plus.
Since the proposed solution helped you it would be appropriate to accept it as an assisted solution and your own solution as the accepted solution.
Avatar of Patmurf

ASKER

I'm sorry to be such a dunce about this, but does your answer mean that I should check "accepted multiple solutions" or is there another place I should be to answer as you suggest?
ASKER CERTIFIED SOLUTION
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 Patmurf

ASKER

With both efforts, the problem was solved.