+ Reply to Thread
Results 1 to 7 of 7

Selecting active cell row and rows below.

  1. #1
    Registered User
    Join Date
    09-10-2009
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2013
    Posts
    47

    Selecting active cell row and rows below.

    Hi there
    I've got some code that locates a cell in column D based on its color. I then want to copy that entire row and all the rows below it to another worksheet. I can only find code that copies to the left or right of the active cell, but not the whole row. There are also some empty rows in the range to be copied.

    Thanks for any help anyone is able to provide.

    datafiend
    Last edited by datafiend; 10-29-2014 at 11:20 PM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Selecting active cell row and rows below.

    I've got some code that locates a cell in column D based on its color.
    Using that code, determine the row number of the found color.

    Calculate the last row of the sheet, then combine the two values to define the range required to copy.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    09-10-2009
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: Selecting active cell row and rows below.

    Thanks for your answer. Unfortunately, my Excel skills are not good enough to understnd it properly. Below is the code I am using which almost does what I want. I copied and modified the code to select the colored range and have added the last line to try and then select the data in the row with the first cell selected and the data below it but can't make it work.

    Please Login or Register  to view this content.
    Private Sub CommandButton2_Click()
    'Standard module code, like: Module1.
    Dim rngMyRange As Range, rngMyFound As Range
    Dim lngMyRows&, lngMyCols&, r&, c&
    Dim strMyAddr$

    Set rngMyRange = ActiveSheet.UsedRange

    lngMyRows = rngMyRange.Rows.Count
    lngMyCols = rngMyRange.Columns.Count

    On Error Resume Next

    For r = 1 To lngMyRows
    For c = 1 To lngMyCols

    'If ActiveSheet.Cells(r, c).Value <> "" Then
    If ActiveSheet.Cells(r, c).Interior.ColorIndex = 6 Then
    strMyAddr = strMyAddr & ActiveSheet.Cells(r, c).Address(False, False) & ", "
    End If
    Next c
    Next r

    'This is the found address string!
    strMyAddr = Left(strMyAddr, Len(strMyAddr) - 2)

    'This is the found Range Object!
    Set rngMyFound = ActiveSheet.Range(strMyAddr)

    'Do something with the found range!
    ActiveSheet.Range(strMyAddr).Select

    'Column D is the first column with a yellow coloured cell. If I use A10478576 in the line
    'below it selects the data from columns A to D; if I use J1048576, selects columns D: J. How can I
    'select columns A:J?
    Range(ActiveCell, Range("A1048576").End(xlUp)).Select

    End Sub
    Please Login or Register  to view this content.
    I can't work out what I need to put to select all the data.

    Thanks for your help

    datafiend

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Selecting active cell row and rows below.

    Please use Code Tags when posting code.

    OK, I think I know what you want, but how are you determining how many columns to copy? Or is it always A-J from the first Yellow Cell in Column D to the end of data?

  5. #5
    Registered User
    Join Date
    09-10-2009
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: Selecting active cell row and rows below.

    Yes, that's right. Always columns A to J from the first yellow cell in D.


    Thanks

    datafiend

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Selecting active cell row and rows below.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-10-2009
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2013
    Posts
    47

    Re: Selecting active cell row and rows below.

    Thanks, Tinbendr. That works perfectly...and so much simpler than all the code I used for selecting the yellow colored cell. I'll try and learn something from it though counting and For...Next usually confuses me.

    datafiend

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Selecting Row of an active Cell
    By edilly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2014, 02:32 PM
  2. Selecting active cell at startup
    By Mihalkanin in forum Excel General
    Replies: 3
    Last Post: 12-08-2012, 05:17 PM
  3. Selecting Active Rows after autofiltering copy, pasting and deleting
    By mopatz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2008, 12:41 PM
  4. Selecting column of the active cell
    By cheaperThanAPro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2007, 10:04 PM
  5. Selecting an active cell
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2005, 03:05 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