+ Reply to Thread
Results 1 to 12 of 12

Identifying and moving(copying) cloumns

  1. #1
    Registered User
    Join Date
    06-20-2007
    Posts
    10

    Identifying and moving(copying) cloumns

    Hi All,
    First - Thanks for the extremely useful information in this forum.

    I am trying to wash some of the data that is exported from a database into excel. I need to pick out the column header that reads "Revenue" and copy all of the data (the whole column) under it to another sheet starting at A25. I've tried combinations of vLookup, hLookup, IF, and etc.... but can't do it. Details below. Any help is greatly appreciated...... Thanks!

    Here is what I am trying to accomplish:

    In row A1, identify which Column is titled "Revenue"
    Copy contents of the "Revenue" column to Sheet1-A25

    Thanks again!

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 2016
    Posts
    1,075
    You could create a macro. With the imported data worksheet open, click on Tools, Macro, Record New Macro. Give the macro a name and click on OK. Go through the motions of selecting, copying and pasting, then stop the macro recorder.

    To run the macro again, click on Tools, Macro, Macros and run your macro.

    I'm a novice at this, but others will be able tell you how to make the macro available in other workbooks if you don't use the same workbook every time.
    Trish in Oz
    -------------
    A problem well defined is a puzzle half solved


    If you attach a sample of your workbook it will be easier to find a solution. Remember to remove/replace sensitive data before uploading the file. Look here if you need help with attachments:
    http://www.excelforum.com/faq.php?fa...b3_attachments

  3. #3
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    I tried creating a macro by manually selecting, copying and pasting to the necessary cell, but it doesn't work - error. That was my first attempt at Macros, but it seems more complicated than what I want to do. Does anyone have a simpler idea?

  4. #4
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    I got the macro to do part of what I need, but not all of it. The thing it lacks is the "intelligence" of automatically searching ROW1 and identifying the REVENUE column and then copying and pasting it to the correct sheet.

    Not sure how to make it do everyting, but I'm guessing some formula is necessary.....Please see my original post. Any ideas? Please help!

  5. #5
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    Here is the Macro I have so far.....

    Sub REV()
    '
    ' REV Macro
    ' Macro recorded 6/20/2007
    '

    '
    Sheets("Siebel_Raw").Select
    Range("E1:E1000").Select
    Selection.Copy
    Sheets("Thermometer").Select
    Range("A25").Select
    ActiveSheet.Paste
    End Sub

    On the second line - "Range("E1:1000").Select" - the range represents the Revenue column I need to copy to the other sheet. However, I need the macro (and/or formula) to identify exactly which column "Revenue" is, because its always a different column. How do I make the macro/formula find the appropriate column before copying it to the other sheet? Thanks!!!

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Wahmba, I think this macro might do everything you need:
    Please Login or Register  to view this content.
    Change "Sheet2" to your sheet's name that you want to paste into. This code also assumes that, in your header row from the first sheet, the column header cell you're seeking is "Revenue", not "2007 Revenue" or "Revenue 1", just "Revenue".

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Based on your latest post, here is one that includes your sheet names:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    Thanks pjoaquin! You have been a great help. I am starting to understand macros a little bit. I do have one problem with the following line of your code:

    "Sheets("Siebel_Raw").Range(Cells(2, i), Cells(iLastRow, i)).Copy"

    I get "run-time error 1004"
    "application-defined or object-defined error"

    I tried edit it, but to no avail. Any ideas?

    Thanks!

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Unfortunately I don't know why the code isn't working for you. I have run it on my home and work PC's and it works just fine. Perhaps your sheet names aren't exactly "Siebel_Raw" and "Thermometer"? Make sure there's no trailing/leading spaces or spelling errors. Also, make sure the cell you're looking for in row 1 on sheet Siebel_Raw is spelled exactly "Revenue", not " Revenue " or any other alternative.

    I've attached my example sheet (zipped) to show you it ran just fine and pulled the correct revenue numbers to the Thermometer sheet.

    hth
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    Your example did the trick! I see you have your tabs in a different order than I do. I moved mine to match yours and it worked fine. I assumed that the order of the tabs didn't matter, because they are referenced by name. I would like to keep my original tab order (Thermometer, Siebel_Raw) if possible. What part of the code would I edit to reflect this?

    Thanks!!

  11. #11
    Registered User
    Join Date
    06-20-2007
    Posts
    10
    I added this in your example and it seems to have done the trick!

    Sheets("Siebel_Raw").Activate

    It looks like this now....

    Next
    iLastRow = Sheets("Siebel_Raw").Cells(65536, i).End(xlUp).Row
    Sheets("Siebel_Raw").Activate
    Sheets("Siebel_Raw").Range(Cells(2, i), Cells(iLastRow, i)).Copy
    Sheets("Thermometer").Activate
    Sheets("Thermometer").Range("A25").PasteSpecial (xlPasteValues)
    Application.CutCopyMode = False

    pjoaquin you are awesome! Thanks for the info - it is GREATLY appreciated!!

  12. #12
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    I think I figured out the issue. For my code to work your focus would have to be on the "Siebel_Raw" sheet. I've added a line (in red) so that it doesn't matter which sheet has the current focus.
    Please Login or Register  to view this content.
    -- ah, glad to see you got that figured out. You're welcome, too.

+ 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