+ Reply to Thread
Results 1 to 14 of 14

always start in certain cell/row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    always start in certain cell/row

    HI,

    I have a macros that copy’s certain bits of data forma row, then copies it to another sheet, however I always need it to start in column A. E.g. if my active cell is C3, I want to start in A3, likewise if the active cell is E3, I want to be able to start in A3.

    As always the help is greatly appreciated

    Antony
    Last edited by antony moseley; 01-19-2010 at 10:37 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: always start in certain cell/row

    Hi,

    Just reposition the cursor with some code like:
    Range("A" & ActiveCell.row).Select
    In practice it's best to avoid .Select or .Activate instructions. They are rarely needed since usually you only need to reference a range to do something with it. However if your existing macro needs A? whatever selecting then just use the above.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: always start in certain cell/row

    This can be done several ways. One way to reference the cell in Column A woth the same row as the active cell is
    Cells(ActiveCell.Row, 1)

  4. #4
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    Quote Originally Posted by blane245 View Post
    This can be done several ways. One way to reference the cell in Column A woth the same row as the active cell is
    Cells(ActiveCell.Row, 1)
    What other way is there to do this?

    I neglected to say - lesson learnt!!!

    On the same row i have the need for two start places - eg columns A to G i need to start at A, but in column H to N i need to start at H.

    I kind need to be if in an celll in column C, go back two cells/columns or if in column J alos go back two cells/column.

    Apologoies for not stating this in my first post

    Antony

  5. #5
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: always start in certain cell/row

    Here are two range variables that contain the cells in columns A and H based on the active cell
    Dim CellA As Range
    Set CellA = Range(Cells(ActiveCell.Row, 1).Address)
    Dim CellH As Range
    Set CellH = Range(Cells(ActiveCell.Row, 8).Address)

  6. #6
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    Quote Originally Posted by blane245 View Post
    Here are two range variables that contain the cells in columns A and H based on the active cell
    Dim CellA As Range
    Set CellA = Range(Cells(ActiveCell.Row, 1).Address)
    Dim CellH As Range
    Set CellH = Range(Cells(ActiveCell.Row, 8).Address)
    HI,

    I am usnure as to how i should use the above... any tips?

    Thanks

    Antony

  7. #7
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: always start in certain cell/row

    I you can post a copy of your file (with nonsensitive data, of course), then we can better help you with your problem. For now, the range variables, CellA and CellH, can be used as the source to copy from one worksheet to another.

  8. #8
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    HI,

    File attached.

    Bascailly the active cell could be left as any one of B,C,D,E,F,G or H after someone has filled in the info - but i want to be able to copy the data from A to I to another sheet to create an e-mail so end off.

    Likewise in with the otehr side left in K,L,M,N,O,P,Q, but i want to be able to copy the data from J to R etc etc

    Trust the above makes sense

    Thanks

    Antony
    Attached Files Attached Files

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: always start in certain cell/row

    Dim rngCopy as Range
    Select Case Activecell.column
       Case <= 8
          Set rngCopy = cells(activecell.Row, 1).Resize(, 9)
       Case else
          Set rngCopy = Cells(activecell.row, 10).Resize(, 9)
    End Select
    for example.
    Everyone who confuses correlation and causation ends up dead.

  10. #10
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    Quote Originally Posted by romperstomper View Post
    Dim rngCopy as Range
    Select Case Activecell.column
       Case <= 8
          Set rngCopy = cells(activecell.Row, 1).Resize(, 9)
       Case else
          Set rngCopy = Cells(activecell.row, 10).Resize(, 9)
    End Select
    for example.
    Hi,

    Nothing happens with the above code - i asumming that it should be selecting the set of data???

    Antony

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: always start in certain cell/row

    No - it merely assigns the relevant range to a variable. What you do with it after that is up to you!

  12. #12
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    Quote Originally Posted by romperstomper View Post
    No - it merely assigns the relevant range to a variable. What you do with it after that is up to you!
    HI,

    I think the grey stuff must not be working....

    If i ran the code and try to do a copy function after all it does is copy the cell that the cursor was left in... i am unsure as to what i should be putting next in the code to get it to copy/select the range

    A

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: always start in certain cell/row

    rngCopy.Copy
    should do it.

  14. #14
    Forum Contributor
    Join Date
    11-24-2008
    Location
    leicester
    MS-Off Ver
    Microsoft 365
    Posts
    161

    Re: always start in certain cell/row

    spot on!!!


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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