+ Reply to Thread
Results 1 to 6 of 6

Generically Referencing a Column

  1. #1
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Generically Referencing a Column

    I have some data that is imported into a spreadsheet, and depending on the data file that is imported, certain data will end up in a different column than it will for other files. In my attached sample spreadsheet, the data I am trying to work with is in Column M. As of right now, my VBA code is as follows:

    Please Login or Register  to view this content.
    This code takes the various pieces of data in M7 on Sheet1, copies it to B1 on Sheet2, and puts each piece of data in its own column. I then go back to Column M on Sheet1, pull all the rows that have the hexidecimal data in them, and paste them on Sheet2, starting in B2:

    Please Login or Register  to view this content.
    What I now need is a way to do this without specifically referencing Column M. The route I tried to take is that on row 7 in Sheet1, the column before the data that is in row M in my sample sheet will always have the value of "TRIG." So, I have tried to write code that looks for the column after "TRIG" and then does the actions I already have working. I have only tried it for the first segment of code above, and here's what I've tried:

    Please Login or Register  to view this content.
    I know that I am referencing some things wrong (i.e., columns.count looks at every possible column in Excel instead of just the ones that have data), and I need help!! Can someone please help me with this? If so, can you help me incorporate both of the top segments of code into the main loop? Thanks in advance for your help!
    Attached Files Attached Files
    Last edited by JP777; 04-25-2012 at 02:34 PM. Reason: trying to tag my code

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Generically Referencing a Column

    Please Login or Register  to view this content.
    will give you the column number for the trig column without looping.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

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

    Re: Generically Referencing a Column

    JP777,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    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]

  4. #4
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Generically Referencing a Column

    JosephP,
    Could you elaborate a little on where to put that line of code? I'm not familar with that terminology...Thanks

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

    Re: Generically Referencing a Column

    JP777,

    As per forum rules, please put code tags around the codes in your first post.

  6. #6
    Registered User
    Join Date
    04-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Generically Referencing a Column

    JosephP,
    I was able to figure out how to use the match function. It helped a lot. Thanks!

+ 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