+ Reply to Thread
Results 1 to 4 of 4

trying to set a cell as a variable

  1. #1
    Registered User
    Join Date
    08-31-2021
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 2016
    Posts
    2

    Question trying to set a cell as a variable

    Hey Everyone,

    I'm very new to excel and vba, I'm trying to set a cell as a variable so i can change the variable instead of replacing every reference to it and write to it as practice but my code doesnt seem too do anything it compiles but doesnt show a visible result

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: trying to set a cell as a variable

    cellc2content is dim'med as a string, but you then use a Set statement when assigning a value to it. When I copy your code into a module, I get an error "object required" error message for that statement. If I delete the "Set" keyword, then the code runs and the number 21 appears in B3 of the active sheet.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    08-31-2021
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 2016
    Posts
    2

    Re: trying to set a cell as a variable

    so i cant use set for strings or am i just using the set command wrong in general??

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: trying to set a cell as a variable

    The Set statement is used to assign a reference to an object to an object variable. The Let (the Let keyword is optional and often omitted) statement is used to assign "basic" values to "basic" types of variables. In this cases, String and Integer (and Double and Long and such) are "basic" data types, and assigning values to such variables uses the Let statement (again, remember that the Let keyword is commonly omitted). I'm not sure that I fully understand the difference, but "object" is a different kind of data type, and assigning those uses the Set statement.

    Beyond that, it probably requires someone who really understands the internal architecture behind the VBA programming language to explain the difference between "basic" data types and "object" data types and the difference between Let and Set.

+ 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] Macro to select a variable cell range and copy it down a variable amount of times
    By JPoFresh in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-18-2019, 09:17 PM
  2. Replies: 5
    Last Post: 06-18-2015, 09:10 AM
  3. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  4. Replies: 4
    Last Post: 05-07-2014, 03:08 AM
  5. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  6. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  7. Replies: 2
    Last Post: 07-24-2012, 11:47 AM

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