+ Reply to Thread
Results 1 to 6 of 6

How to set Range as a User-Defined variable

  1. #1
    Registered User
    Join Date
    11-03-2006
    MS-Off Ver
    365
    Posts
    63

    How to set Range as a User-Defined variable

    Hi, I'm a complete beginner to VBA and I'm really just doing this for sun (sorry for any newbie questions!).

    Anyways, I would like to write code that prompts the user to enter which Column should be copied into Column A and then have the code set Column A = to the chosen column.

    For starters, I have this simple code which gives me a 1004 error (Method Range of Object_Worksheet failed). Can anyone guide me as to what I'm doing wrong here:

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 12-05-2019 at 12:49 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How to set Range as a User-Defined variable

    Hi
    try
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: How to set Range as a User-Defined variable

    It would be more efficient to restrict the range to the number of rows in use rather than all of the cells in the column, but since that is what your code does, consider writing your Click event code like this...
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: How to set Range as a User-Defined variable

    Change your code to:

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: How to set Range as a User-Defined variable

    Quote Originally Posted by alansidman View Post
    Change your code to:

    Please Login or Register  to view this content.
    Just pointing out for the OP benefit that you changed the InputBox requirement from the Column Number that the OP's original code asked for to inputting the Column Letter instead.

  6. #6
    Registered User
    Join Date
    11-03-2006
    MS-Off Ver
    365
    Posts
    63

    Re: How to set Range as a User-Defined variable

    Perfect, thanks all. Actually, I think the string approach works better here for my purposes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] User defined type: assign a variable to another variable
    By BNCOXUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2019, 10:51 AM
  2. Global user-defined variable within a userform
    By ChrisB_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2015, 08:49 AM
  3. Copy, paste, replace- user defined range in all the defined sheets
    By aganesan99 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2014, 12:28 PM
  4. User-defined variable to declare or modify range parameters
    By rcheek in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2013, 08:25 AM
  5. Macro to Insert defined integer into range defined by variable criteria
    By stereofeedback in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2013, 12:33 PM
  6. Changing user defined variable types
    By Mbrolass in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2007, 11:27 AM
  7. How to: User Form to assign a user defined range to a macro variab
    By TrevTrav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2005, 04:06 PM

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