Hello. I'm just practicing coding and I was curious as to how you write multiple offset commands for moving around a sheet? Would I just repeat code below, or is there a more efficient way to do it?
ActiveCell.Offset(0, 1).Select
Hello. I'm just practicing coding and I was curious as to how you write multiple offset commands for moving around a sheet? Would I just repeat code below, or is there a more efficient way to do it?
ActiveCell.Offset(0, 1).Select
If you could post a sheet and explain what you want to do it would be better.
Generally it's better not to select cells, it's not necessary and this makes the code run much slower.
If you refer to specific sheets in your code then you can manipulate these cells without selecting them.
Small example below, but post a sheet give me some examples of things you would like to do and I will help you.
This will loop through the first 10 rows in the first column and add the value "Test" to all of them, it also sets the value in the cells 3 to the right to "New Test".
The sheet doesn't have to be selected, nor do the cells.
All of this is done on a sheet with the tab name of "One".
I guess I should specify. If you refer to the sheet specifically you don't have to be on that sheet. If you don't refer to a sheet specifically the code will run on the cells in the currently active sheet, which might be okay, but if you or someone else runs the code and forget to switch to the sheet you want the code to manipulate you will have undesirable results.
Referring to activecell can also cause issues if you activate the wrong cell or forget to activate the desired cell before starting the code.
![]()
Please Login or Register to view this content.
Last edited by skywriter; 03-17-2015 at 05:16 PM.
What do you mean by " moving around a sheet"
Can you give examples
- Battle without fear gives no glory - Just try
Sure, it's just a simple exercise. Go from cell A1 to A3 to B7 to B9 to C18 etc. The order doesn't matter, the point is to just move around and understand the code.
See some possibilities attached.
Test using F8 to go step by step
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks