+ Reply to Thread
Results 1 to 3 of 3

How do you insert a variable number of blank rows?

  1. #1
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    How do you insert a variable number of blank rows?

    It's been a while since I attempted anything with VBA and I was never very good to please bear with me.

    I have a basic form with tenant information and what I've been doing if I need to add more is to manually go in and insert blank rows (16 of them) for each tenant. Then I copy and paste the form I have for the other tenants each time.

    So I'm starting the process to automate it and I've run into an issue with inserting the number of new rows that depends on the number of tenants. I did an input box and assigned the answer to a variable and then multiplied it by 16 to show how many rows past the initial one (row 162) I need to add.

    So if it's one tenant I need to insert new rows into 162:178, with 2 tenants 162:194, etc.

    How do you tell excel to use a variable for the rows selection?

    Here is what I have so far.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How do you insert a variable number of blank rows?

    How do you tell excel to use a variable for the rows selection?
    Sorry, I don't quite understand what you mean,
    but maybe something like this ?
    Please Login or Register  to view this content.
    The code above will select the rows as many as the value in EndTenInput starting from cell A162.
    If the EndTenInput value is 16, then it will select the rows from A162 to A177 ---> 16 rows.
    If the EndTenInput value is 5, then it will select the rows from A162 to A166---> 5 rows.
    But Range("A162") in the code is hardcoded, not a variable.

    Alternative way :
    Please Login or Register  to view this content.
    The above code will select 17 rows starting from A162 to A178.
    If you want it select the rows as many as the value of EndTenInput (for example EndTenInput value is 16),
    then you need to subtract the offset EndTenInput by 1 :
    Please Login or Register  to view this content.
    The above code will select 16 rows starting from A162 to A177.
    But again, Range("A162") in the code is hardcoded, not a variable.
    Last edited by karmapala; 02-25-2022 at 01:58 AM.

  3. #3
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How do you insert a variable number of blank rows?

    Glad I can help.
    Thanks for the rep, max3732

+ 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] Insert variable number of rows into different sheet and shift down
    By richardturnbull in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-29-2015, 06:17 AM
  2. Macro to insert a variable number of rows into a variable location
    By TheClaw2323 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-08-2015, 05:31 AM
  3. [SOLVED] Macro code to insert 3 rows on spreadsheet with variable number of rows
    By D18GE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2013, 07:33 AM
  4. [SOLVED] Macro to insert blank rows so that the total number of rows with data is equal to 1021
    By nsm1411 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 10:25 AM
  5. Insert Blank Rows where the number of rows come from a Value from a formula
    By akwishestofish in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2012, 01:58 PM
  6. Need to insert formula to a variable number of rows
    By edoc abv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2005, 12:05 AM
  7. [SOLVED] insert variable number of rows
    By tina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2005, 10:06 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