Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 10th, 2009, 07:11 PM
Registered User
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default New to Excell VBA - need to select a row

I need to write a macro that deletes some rows in a spreadsheet, then advances a certain number of rows, and deletes a different number of rows, advance an arbitrary number of rows, delete, etc. I have no idea how to use a variable to increment the selected cells each time.

I need to do something like:

Do this m times: {

Delete rows "r1 through r2"

Advance n1 rows

Delete delete rows "r3 through r4"

Advance n2 rows}


Sorry for this clueless post...
Old March 10th, 2009, 10:13 PM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts

Here are some examples that might help you

To delete second row:


To select second row:


To delete multiple rows - second and third


to loop through rows

For i1 = 1 To 200 Step 2
Rows(i1).EntireRow.Font.Color = vbRed
Next i1

Try it out. Hope it helps you a bit

C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Old March 18th, 2009, 09:41 PM
Authorized User
Join Date: Jan 2009
Posts: 20
Thanks: 2
Thanked 0 Times in 0 Posts

Here is another example that may help.

vRCnt = 1
while activecell.value <> ""

Old March 18th, 2009, 10:01 PM
Authorized User
Join Date: Jan 2009
Posts: 20
Thanks: 2
Thanked 0 Times in 0 Posts

Here is another example that may help.

You can set your variables to increment by adding the variables using a Wend statement.
Basically a wend works the same as a loop. Refer to a vba reference guide. John Walkenback has good books.

vSR = 1
vLR = 6
vIncR = 7
while activecell.value <> ""
do what your going to do and then increment your variables
vSR = vSR + 3 Lets say now you want your starting row variable to = 4
vLR = vLR + 6 Lets say now you want your last row variable to = 12

Hope this helps some now or in the future.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
Using Excell Funtion in VBA coolrks BOOK: Excel 2003 VBA Programmer's Reference 1 February 8th, 2006 11:26 AM
Excell/VBA AddinInstall event BrighterLater Excel VBA 1 July 22nd, 2005 06:27 AM
Select row number N 1kHz SQL Language 4 December 27th, 2004 06:22 AM
How to select every N row in CR nan Crystal Reports 4 September 3rd, 2004 07:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.