Solved

How to loop through range of cells in Excel VBA?

Posted on 2008-09-30
2
936 Views
Last Modified: 2010-05-18
I am trying to use a For LOOP to alternate throught the range of cells in Excell but do not quite remember the syntex.   Here is what i am trying to do:  

On row 1 select first three cells (for example:  A1, B1, C1) and do something with it.  
Then next loop around should select next three cells on Row 1 (example:  D1, E1, F1)  and do somthing with it
Then next loop around should select next three cells on Row 1 (for example: G1, H1, I1) and do something with it.

I sort of started this but do not quite know how to alternate through Range("?1:?1")

For K = 1 To  30
    Range("?1:?3").Select
    Selection.Merge
    ActiveCell.FormulaR1C1 = "Question" & K
 Next K
 
In the place of questions mark not sure what to put...

Any help is appreciated.    
 
0
Comment
Question by:bengoa
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22607035
For K = 1 To  30 Step 3
    Range(Cells(k, 1), Cells(k + 2, 1)).Select
    Selection.Merge
    ActiveCell.FormulaR1C1 = "Question" & K
 Next K
0
 

Author Closing Comment

by:bengoa
ID: 31501610
thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Google Sheets Script question. 2 20
Add a range in an Excel graph 5 36
excel help 4 21
tricky if formula 2 0
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now