Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I select a range of cells, relative to the cursor position?

Status
Not open for further replies.

SimonDavis

Technical User
Joined
Mar 16, 2001
Messages
613
Location
GB
I'm trying to make some code to run through a sheet and change it to alternating white and green stripes (similar to a computer printout).

I need to run the process often, as sorting the data almost always messes it up.

So, I'm going to make a code that goes to the first cell, selects horizontally to the other side of the sheet, fills green, then offsets (down) by 1, selects and changes to white. Then I offset and run the code again, in a loop. I can do all of that, except get it to select the range . . .

So, could anyone help with the code to get the cursor to select a range from the current cell, to the cell say 15 columns to the right? Absolute references won't work of course.

This is Excel 2002, and vb 6.3

Thanks
 
As a starting point, the cursor position will be .Selection

Everybody body is somebodys Nutter.
 
You may do better if you are in the right forum. Try forum707 which deals specifically with VBA

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Chris - thanks. The first cell isn't a problem, as that is absolute. Meantime, I did manage to solve it with the code below.

John, thanks. We all appreciate you being thread cop. really.

Range("B3").Select
For j = 1 To 68
Range(ActiveCell, ActiveCell.Offset(0, 9)).Select
Selection.Interior.ColorIndex = 35
ActiveCell.Offset(1, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, 9)).Select
Selection.Interior.ColorIndex = 2
ActiveCell.Offset(1, 0).Select
Next j
End Sub
 
Simon, it's not a question of thread cop! The site is organised in this way so that you can get the specific help you need from the people who specialise in that info. Posting in the wrong forum will get you less than optimal answers. It also leaves your helpful and useful contribution orphaned where the other VBA users may not find it.

See faq222-2244 for more guidance on forum usage.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
OK, you're right. It was just the second one I'd seen from you.

Sorry.

 
Interesting - didn't think of that. A hidden column of numbers and formatting on whether they're odd or even - much simpler.

Thanks - I have come across that site before, it is indeed a good place to find solutions.

 
OK, last post - the formula on his page is even better (of course).

Works like a charm. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top