+ Reply to Thread
Results 1 to 6 of 6

Question on Range() syntax in VBA

  1. #1
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Question on Range() syntax in VBA

    Hi all,

    Basically I just want to know what this line does and it's tough to google.

    Please Login or Register  to view this content.
    I understand that it's a For loop that will look through each cell in the b3:end of data

    However, I don't really understand the syntax of the Range() part. Can someone explain why the & is used and how that fits in? Thanks!

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Question on Range() syntax in VBA

    The part after the & is grabbing the end of column B so it can build the range ... B3:B100. (That's just an example. I don't know that 100 is the end)
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Re: Question on Range() syntax in VBA

    So it's concatinating the b3:b and the row number where the last piece of data is found?

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

    Re: Question on Range() syntax in VBA

    Quote Originally Posted by armando12345 View Post
    So it's concatinating the b3:b and the row number where the last piece of data is found?
    Yes, sort of... it is the row number for the last piece of data in Column B (which is not necessarily the last piece of data on the entire worksheet).

    I would also note that this line of code can be written without using concatenation by just giving the Range object a starting and stopping cell...

    For Each cell In Range("B1", Cells(Rows.Count, "B").End(xlup))
    Last edited by Rick Rothstein; 10-08-2019 at 04:37 PM.

  5. #5
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Re: Question on Range() syntax in VBA

    Makes sense that you could write it how you did...

    That basically takes "B1" as the starting cell in the range, and the second cell in the range is Cells(lastrowinfile, in column b) then xlup which is basically ctrl + up arrow.

    Am I getting that right?

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

    Re: Question on Range() syntax in VBA

    Yes... where the CTRL+UP Arrow is performed from the last cell in the column.

+ 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. VBA code to copy line items from form - overriding previous line item
    By dkostyan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2016, 11:19 AM
  2. Line Graph question - vetical line values at one fixed date
    By bohn in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-12-2015, 02:22 PM
  3. VBA line of code question, what does it mean
    By trhardy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2013, 06:38 PM
  4. Quick question regarding line break within code & variable within prompt box
    By jasondu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2012, 12:06 PM
  5. Line Chart Question - break in line for blank cells
    By JonPugh in forum Excel Charting & Pivots
    Replies: 11
    Last Post: 12-09-2009, 09:39 AM
  6. Line graph question: one line per value
    By redlynx in forum Excel General
    Replies: 2
    Last Post: 12-31-2008, 05:58 AM

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