Results 1 to 5 of 5

multiple offset commands

Threaded View

  1. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: multiple offset commands

    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.

    Sub Example()
    Dim wsOne As Worksheet
    Dim r As Long
    
    Set wsOne = Worksheets("One")
    
    For r = 1 To 10
    
    With wsOne
     .Cells(r, 1).Value = "Test"
     .Cells(r, 1).Offset(, 3).Value = "New Test"
    End With
    
    Next r
    
    End Sub
    Last edited by skywriter; 03-17-2015 at 05:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA commands for multiple cells?
    By JLoKyM in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2013, 07:32 AM
  2. Multiple IF & +IF commands
    By simpleton58 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-29-2013, 01:37 PM
  3. Macro Recording Chart Format commands missing all important commands!!!!
    By nounours in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2013, 09:20 PM
  4. Multiple Commands
    By jpxexcelforum in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-08-2011, 04:37 AM
  5. Multiple If Commands
    By markswan20 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-17-2008, 05:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1