+ Reply to Thread
Results 1 to 7 of 7

Worksheet consolidation, VBA. Stop copying column headers

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Worksheet consolidation, VBA. Stop copying column headers

    Hi there,

    I took another mate's sheet and applied it to my workbook to play around but ran into one problem.

    The copied the range displayed is the header row of the sub worksheet. I double checked the code, but cannot seem to find where the problem is.

    So if you activate the "master" worksheet, all that gets copied over is the column header.

    Anyone able to assist? I must be missing something.

    Please Login or Register  to view this content.
    Thanks
    Attached Files Attached Files
    Last edited by Lifeseeker; 02-21-2012 at 10:57 AM. Reason: adding the code in there

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Worksheet consolidation, VBA. Stop copying column headers

    hi there, the problem hides here:

    Please Login or Register  to view this content.
    If the header in A1 is the only value in the column A, LR will be equal to 1 and further down you will end up with copying

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Worksheet consolidation, VBA. Stop copying column headers

    oh right right....

    great thank you!

  4. #4
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Worksheet consolidation, VBA. Stop copying column headers

    In the code below:
    Please Login or Register  to view this content.
    What does the "&" mean in ws.range("A2:F" & LR)? Is it like the word AND?

    Same thing with
    Please Login or Register  to view this content.
    thanks
    Last edited by Lifeseeker; 02-21-2012 at 09:48 AM. Reason: few more clarifications needed

  5. #5
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Worksheet consolidation, VBA. Stop copying column headers

    Figured out what the last line do. It is for alternating row colors.

    Still need an answer to my first question though.

    Thanks

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Worksheet consolidation, VBA. Stop copying column headers

    if LR=1

    Please Login or Register  to view this content.
    gives Range("A2:F1")

    Please Login or Register  to view this content.
    gives x = "What is it?"

    & - concatenation operator

    VB help reference extract:

    & Operator

    Used to force string concatenation of two expressions.

    Syntax


    result = expression1 & expression2

    The & operator syntax has these parts:

    Part Description
    result Required; any String or Variant variable.
    expression1 Required; any expression.
    expression2 Required; any expression.

    Remarks

    If an expression is not a string, it is converted to a String variant. The data type of result is String if both expressions are string expressions; otherwise, result is a String variant. If both expressions are Null, result is Null. However, if only one expression is Null, that expression is treated as a zero-length string ("") when concatenated with the other expression. Any expression that is Empty is also treated as a zero-length string.
    Last edited by watersev; 02-21-2012 at 10:55 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Worksheet consolidation, VBA. Stop copying column headers

    Ah I see I see.

    Quite an important code element! I had never understood that until now.

    Thank you

+ 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