+ Reply to Thread
Results 1 to 4 of 4

Dynamic Columns and Rows Selecting all Loop

Hybrid View

excel0831 Dynamic Columns and Rows... 02-22-2012, 03:58 PM
arlu1201 Re: Dynamic Columns and Rows... 02-22-2012, 04:26 PM
excel0831 Re: Dynamic Columns and Rows... 02-22-2012, 05:41 PM
excel0831 Re: Dynamic Columns and Rows... 02-22-2012, 04:09 PM
  1. #1
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Dynamic Columns and Rows Selecting all Loop

    Hi,

    I'm using a spreadsheet that is updated often, new rows and columns are added almost daily. I'm trying to use a loop to start as a column select all the data in the column apply the conditional formatting then move to the next column.

    I know how to use a macro and apply the conditional formatting however, I'm struggling with trying to move along each column. Here is what I have so far:

    Dim LastColumn As Long
    Dim lngRows As Long
    Dim rngC As Range
    
                LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    
               lngRows = Cells(Rows.Count, 1).End(xlUp).Row
                Range("A1").Select
                Set rngC = Selection.CurrentRegion
                For j = 6 To LastColumn
               StartCel = Cells(2, j)
                LastCel = Cells(lngRows, j)
                
                Range(StartCel, LastCel).Select
                
                
                Next
    I continue to get an error message saying I'm out of range when the program gets to "Range(StartCel,LastCel).Select".


    In summary I want to just have a loop that goes through the spreadsheet and selects all the data in Column F then in column G,H etc.

    I did not include my code about conditional formatting.

    please help!

    Thank you in advance for taking the time to help me!
    Last edited by excel0831; 02-22-2012 at 05:41 PM. Reason: Solved problem!

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Dynamic Columns and Rows Selecting all Loop

    Change these lines -
     StartCel = Cells(2, j)
                LastCel = Cells(lngRows, j)
    to
    StartCel = Cells(2, j).Address
                LastCel = Cells(lngRows, j).Address
    Without the .Address, it was considering the values in cells(2,j) and cells(lngrows, j).
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Dynamic Columns and Rows Selecting all Loop

    Thank you so much arlu1201!!!!! That worked!

  4. #4
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Dynamic Columns and Rows Selecting all Loop

    Thanks! This is my second time posting code to this forum. Therefore, I was unaware of how to post code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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