+ Reply to Thread
Results 1 to 5 of 5

Add Data Entry Queries to VBA Code

  1. #1
    Registered User
    Join Date
    06-27-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016
    Posts
    37

    Add Data Entry Queries to VBA Code

    Hi,

    I have the VBA code below which inserts a blank row above rows in a particular column when a value is in the code.

    Sub InsertRow()
    Dim Lastrow As Long
    Dim I As Long
    Application.ScreenUpdating = False
    Lastrow = Range("AQ" & Rows.Count).End(xlUp).Row
    I = 1
    While I <= Lastrow
    If (Len(Cells(I, "AQ")) <> Len(Replace(Cells(I, "AQ"), "N", ""))) Then
    Rows(I & ":" & I).Insert Shift:=xlDown
    I = I + 1
    End If
    I = I + 1
    Lastrow = Range("AQ" & Rows.Count).End(xlUp).Row
    Wend
    Application.ScreenUpdating = True
    End Sub

    So in this case when Insert is in a cell in column AQ in adds in a blank row above that cell.

    I want to adapt is to i can add it as a button so the tow important bits of information, the column and the text in the cell are asked for in a pop up to enter for the macro to run.

    Hope that makes sense. Thank you in advance.

    Kind Regards,

    Heath

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Add Data Entry Queries to VBA Code

    Can I just check how you're checking for the word "insert"?

    Unless my brain is pickled this line:
    Please Login or Register  to view this content.
    appears to be saying , If the length of the cell is not equal to the length of the cell after you've removed any letter "N"'s then insert a line....

    This means that any row containing the letter N gets a row inserted above it, is this what you wanted to happen? and if so, is that the same for the solution? ie any cell containing the the required text? so if I enter SAUSAGES as the text you want it to insert a row above cells saying "SAUSAGES", "I LOVE SAUSAGES", "ABCSAUSAGESDEF" etc?

    Heres the code to do the above though, I've made a couple of changes to the logic as well but they're just personal choice, firstly the check above doesn't seem a sensible way to do this, it works but doesn't really make logical sense, use the INSTR function to check if text exists.

    I've also removed the additional check for the LastRow, I get why you're doing it but again it just seems more sensible and probably resource useful to simply increment LastRow whenever you insert a row rather than always checking its value.

    Please Login or Register  to view this content.
    Last edited by pjwhitfield; 09-15-2022 at 05:02 AM.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    06-27-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016
    Posts
    37

    Re: Add Data Entry Queries to VBA Code

    Hi,
    Thank you for your reply.

    It doesn't work quite how its supposed to.

    1) It is inserting a row above anything with the text string in it so if I use Insert and InsertNO in column H it adds a row above both. It needs to be specific to the text entered.
    2) It also needs a 3rd question of how many rows you want to add, or how many times to run the macro.

    Thank you for your time.

  4. #4
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Add Data Entry Queries to VBA Code

    try

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-27-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016
    Posts
    37

    Re: Add Data Entry Queries to VBA Code

    Thank you so much, this works great.

+ 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] Data Entry Form VBA Code
    By drewtom in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2019, 11:13 AM
  2. bar code data entry
    By aby-geek in forum Excel General
    Replies: 1
    Last Post: 04-20-2016, 07:28 AM
  3. [SOLVED] Request for data entry VBA code
    By lorus13 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-23-2015, 11:07 PM
  4. [SOLVED] Userform data entry code
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 18
    Last Post: 12-21-2013, 12:48 AM
  5. Replies: 1
    Last Post: 11-13-2012, 02:06 PM
  6. VBA code to prevent data entry
    By singhabhijitkumar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-04-2010, 03:42 AM
  7. Help w/Indexing code and cell data entry
    By KennyE in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2008, 05:04 PM

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