Results 1 to 4 of 4

Thread: VBA data types

  1. #1
    Seeker xcel's Avatar
    Join Date
    May 2018
    Posts
    7
    Articles
    0
    Excel Version
    2016

    VBA data types



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hey Friends,

    I am new to VBA and was learning some basics data types. I have seen some videos where they declare

    Dim A as range
    Dim ws as worksheet

    I know these are variable declaration but the data types i know are integer, bytes, long, double etc. So, what are these range and worksheet means. what type of declarations are these. Any input is appreciated

    Thanks

  2. #2
    Conjurer Logit's Avatar
    Join Date
    Nov 2016
    Posts
    210
    Articles
    0
    Excel Version
    2007
    .
    Dim A as Range = The variable A represent a range on the sheet. Ex: Range("A1:K1")

    So ... in a macro you might have something like :

    Sub YourMacro()
    Dim A As Range

    Set A = Sheet1.Range("A1:K1")

    ' more code here that will affect A

    End Sub



    Dim ws as worksheet = The variable ws represents a worksheet.

    So ... in a macro you might have something like :

    Sub YourMacro()
    Dim ws as Worksheet

    Set ws = Sheets("Sheet1")

    'more code here that will affect ws

    End Sub

  3. #3
    Seeker xcel's Avatar
    Join Date
    May 2018
    Posts
    7
    Articles
    0
    Excel Version
    2016
    Thank Logit,

    That make more sense now

  4. #4
    Neophyte Richard Wein's Avatar
    Join Date
    Oct 2017
    Location
    UK
    Posts
    4
    Articles
    0
    Excel Version
    365
    Hi xcel. As well as data variables you can also declare objects. Range and Worksheet are two of the many object types in the Excel object model. For more info you may find this page helpful:
    https://www.excelfunctions.net/excel-objects.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •