Deleting a range of rows based on a variable; syntax error

B

Babymech

I have a very basic question about how to express a certain range of rows
that I wish to delete in a macro. It's not tricky (I don't think), I just
haven't been able to find the right help file or webpage to explain the
phenomenon to me (I'm very new at this).

Basically I want to delete a number of rows based on a variable (integer).
If the variable is 1, for example, I want to delete rows 13-26. It is
possible for me to do this with the following line:

Worksheets("Math").Rows("13:26").Delete

The problem is, I can't figure out how I should do this when I want to bring
my variable into it. For example, I would love to be able to use:

Worksheets("Math").Rows(MyVariable * 13:MyVariable*13 + 13").Delete

But that's not the right syntax at all. Any suggestions?
 
M

Mike H

Hi,

myvariable = 1
Worksheets("Math").Rows(myvariable * 13 & ":" & myvariable * 13 + 13).Delete

Mike
 
B

Babymech

Thanks - I could have sworn I had tried that, but I must have gotten some
part of it wrong. Your suggestion solved it perfectly, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top