+ Reply to Thread
Results 1 to 3 of 3

VBA Insert row, then clear contents except for data in column B.

  1. #1
    Registered User
    Join Date
    10-09-2012
    Location
    HOUSTON
    MS-Off Ver
    Excel 2016
    Posts
    19

    VBA Insert row, then clear contents except for data in column B.

    I have a perfectly functioning script that does everything that I need perfectly except for one thing. I have a column that typically (depending on current project) has sequential numbers ranging from 1 to (as many as needed, added as needed). The script I currently have clears these numbers as the final step. Is there a way to re-write this to not clear that range explicitly? I have been googling for two days on a fix for this to no avail.

    Lets say I have 10 rows numbered 1-10. I need an 11th row, so I run script which adds row(s) depending on how many I type into inputbox. This finds the last row (10) with data in column B, then inserts below this row, then copies down entire 10th row, then clears entire new row (11) except formatting and formulas.

    I cannot change sequential number to formulas (=b10+1) as this will break if the worksheet gets sorted by another column which has happened.

    I could provide my workbook but there are numerous sheets and scripts which may confuse the matter.

    I am also open to suggestions to discover last row as I know what I have isn't the cleanest way to do this. This worksheet starts with several hundred rows typically, and can grow to as much as 20,000 but should never get to the B200000 I use to get clear of any data.

    My main concern currently is retaining numerical values in column B which has named range of "Weld_No" while inserting rows and preserving formatting and formulas. The reason for inserting rather than just copying down is I have named ranges which I need to stay inside of. I don't use the entire column as a named range because I have formulas which count blanks and it the entire column is named range it would throw this count off. I am also currently looking into converting my name ranges to OFFSET formula so they would grow with the data but that's off topic too.

    I tried to address any questions or suggestions that I figured would come up.

    Here is the current code I need to tweak.

    Please Login or Register  to view this content.
    Thanks in advance.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Insert row, then clear contents except for data in column B.

    Why not just use a Table? It will automatically fill formulae in new rows... And if you need a table row number, you could use a formula like =ROW()-1, for example...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    10-09-2012
    Location
    HOUSTON
    MS-Off Ver
    Excel 2016
    Posts
    19

    Re: VBA Insert row, then clear contents except for data in column B.

    I have looked at a tables before, however they affected something negatively which I cant recall currently. Maybe it was column headers, conditional formatting, something that was a deal breaker. Thanks for the suggestion.

    The scope needs to be limited to VBA solution. Modifying the sheet is not viable solution as this is corporate workbook which is distributed and used at multiple locations and for continuity and familiarity what the user sees should not be modified.

    Thanks again.

+ 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] Clear contents of column(L) after every one row
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-02-2017, 06:00 AM
  2. Loop to clear cell contents by column (but not entire column)
    By codys21 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-11-2016, 03:26 PM
  3. VBA to clear contents of the cell in a column of data in a cell starts with specific word.
    By winmaxservices1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2015, 08:25 AM
  4. Clear Contents of column based on data in another column
    By wachao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2014, 02:39 AM
  5. [SOLVED] Clear contents of last column with data
    By avanir151 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2014, 03:45 PM
  6. [SOLVED] Clear Contents in an insert rows x number of times Macro
    By Rachael Whyment in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2013, 10:11 AM
  7. Clear Contents on Column
    By martinez_pedro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2012, 06:40 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