+ Reply to Thread
Results 1 to 2 of 2

How to correctly write a range in a macro with variables as row numbers?

  1. #1
    Forum Contributor
    Join Date
    02-27-2020
    Location
    Rotterdam, The Netherlands
    MS-Off Ver
    2013
    Posts
    425

    How to correctly write a range in a macro with variables as row numbers?

    Hi,

    I would like to create a macro that selects a certain area in a dynamic range. FirstRow and LastRow are variables.
    I wrote:

    Please Login or Register  to view this content.
    ....and get an error message.

    However,

    Please Login or Register  to view this content.
    ....works fine.

    What am i doing wrong?
    Any input is much appreciated!
    Last edited by MaartenRo; 06-16-2020 at 07:22 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to correctly write a range in a macro with variables as row numbers?

    range("H" & FirstRow & ":H" & LastRow).select
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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] How to write =IF((E2>75%)+E2*300) correctly
    By TPS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-10-2018, 10:52 AM
  2. [SOLVED] Why does code called from a macro button to write data to an excel table work correctly, b
    By mgeoyoung in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2017, 08:57 PM
  3. [SOLVED] How to correctly place a range of numbers in COUNTIFS and SUMIFS formulas?
    By nerkaszatana in forum Excel General
    Replies: 2
    Last Post: 06-07-2016, 11:35 AM
  4. Pick cell value based on two variables from range of numbers
    By andre1986 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-24-2015, 01:51 PM
  5. Excel 2010 Macro Not Referencing Numbers Correctly
    By datadigger in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2012, 07:58 PM
  6. Excel 2010 Macro Not Referencing Numbers Correctly
    By datadigger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2012, 12:41 PM
  7. How to write this loop macro correctly?
    By cb95amc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2009, 08:38 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