+ Reply to Thread
Results 1 to 3 of 3

Variable Name in a Range Table Object?

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    55

    Variable Name in a Range Table Object?

    Hi all,

    I'm a bit stuck on this so any help would be very much appreciated!

    Basically I'm trying to do two thing: (1) Create a name of a table using a string variable (this works okay) and (2) Copy and paste some data from a column into another column which has the same name generated in (1).

    For example:
    - Cell A1 = July.
    - period_name = July Month
    - Copy from a column (in this case called period data) within a table object.
    - Paste into the same table with the column name as defined by my variable (i.e. July Month).


    This is my macro as it stands. I have bolded where the variable is included in the range name of the table object as I'm pretty sure this is where it is going wrong


    Dim period_name As String

    period_name = Sheets("Sheet1").Range("A1") & " Month"

    Sheets("ZZZ Data").Range("ZZZ_Data[Period Data]").Copy

    Sheets("ZZZ Data").Range("ZZZ_Data[period_name]").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    End Sub


    Many thanks,

    Coeus.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,538

    Re: Variable Name in a Range Table Object?

    Try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Variable Name in a Range Table Object?

    Please Login or Register  to view this content.
    period_name can't have a space in it.

    Please take a few minutes to read the forum rules and edit your post to add CODE tags.
    Entia non sunt multiplicanda sine necessitate

+ 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