+ Reply to Thread
Results 1 to 6 of 6

Column as a variable

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Column as a variable

    I have this code that I am updating - I used to use a Constant for the column number. However, this led me to write the code 30 times for different customers. Now I am using a variable for the code but I cannot figure out how to change the Column number to use the variable:

    Please Login or Register  to view this content.
    The variable name is lgColumn. How do I replace the column number with this variable?

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,372

    Re: Column as a variable

    Hi,

    I've started using Cells(row, column) instead of Range in my VBA. This allows me to increment the column number.

    Then to address all cells in a range you can set two sets of counters like:

    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Column as a variable

    Thank you for your help but I do not want to use a loop. It takes longer to run. I know it is possible to populate the whole column in one shot - I just do not know how.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Column as a variable

    Please tell me how much longer it will take using a loop....

    Please Login or Register  to view this content.



  5. #5
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Column as a variable

    With a loop it depends on the amount of rows. When you loop through, it does each row as a different operation as opposed to the other method will do the whole column at once. I cannot tell you exact time difference because it matters on a lot of different things.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Column as a variable

    Yes I know it's indiscernable: ergo peanuts.

+ 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