+ Reply to Thread
Results 1 to 10 of 10

If entered value starts with "W" Move it.

  1. #1
    Registered User
    Join Date
    01-30-2020
    Location
    fresno
    MS-Off Ver
    2017
    Posts
    14

    If entered value starts with "W" Move it.

    Hello all,

    I am really new to VBA and could use some help on a task i'm working on:

    I am trying to code a sheet where if the value entered starts with a "W" it cuts it and moves it to the second-to-next blank column in row 1. I am using a scanner that scans bar codes and immediately presses return when scanned. When I scan codes that start with a "w" I essentially want to start a new column:
    sample workbook.jpg

    If That W# already exists I want to then move down to the next blank cell in the row that the W# is the header for and make that the new active cell to be able to scan under:
    sample workbook2.jpg

    Any help would be appreciated, let me know if you need more info.

    thank you

  2. #2
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: If entered value starts with "W" Move it.

    Do you know which events are triggered by the scan input?
    If a "Worksheet_Change" or "Worksheet_SelectionChange" is triggered then there will be an easy solution

  3. #3
    Registered User
    Join Date
    01-30-2020
    Location
    fresno
    MS-Off Ver
    2017
    Posts
    14

    Re: If entered value starts with "W" Move it.

    Yes, it looks like it triggers a "Worksheet_Change"

  4. #4
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: If entered value starts with "W" Move it.

    It is not possible to copy the data to a location if you do not know where it should be.
    So one possibility is that you always use the same sheet for import scan data check for your "W" and compare with your available data.
    Then copy it to another sheet as needed (either adding to available or start a new one) and erase the scan data from the input sheet.

    each scan is a single line?
    Last edited by gue2013; 02-10-2020 at 05:07 PM.

  5. #5
    Registered User
    Join Date
    01-30-2020
    Location
    fresno
    MS-Off Ver
    2017
    Posts
    14

    Re: If entered value starts with "W" Move it.

    We should be able to know where to paste the data. It will always go 2 to the right of the last used column in line 1. It would look something similar to this I believe:

    "Copy Destination:=Sheet3.Cells(1, a).End(xlToRight).Offset(0, 2).Select.Paste"

    so if a W is entered in a10 and c1 is blank it would cut and paste to c1 and i would want c2 to be the next cell that is selected. when the next W value is scanned lets say c7 for example, then it would cut and paste to e1 and e2 would be selected.

    I also need to check if the new W value corresponds to one already inputted in A1, C1, E1, and so on. so if we are in e11 and we input a W value that is the same W value as a1 it would remove the value inputted in e11 and not paste anywhere but a10 would be selected because that is the first blank row in the a column.

    I know there is a code that we could write to accomplish this logic, I am just very new to VBA. let me know if that makes sense or if it cannot be done as I think.

  6. #6
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: If entered value starts with "W" Move it.

    still missing info
    What data do you get for each scan?
    only "W..." ? or
    "W.." and one line (two cells) ? or
    "W.." and unpredictable number of lines till a next "W.." ?

  7. #7
    Registered User
    Join Date
    01-30-2020
    Location
    fresno
    MS-Off Ver
    2017
    Posts
    14

    Re: If entered value starts with "W" Move it.

    for each scan I only get "W.....". the lines without W and just numbers are separate scans of different barcodes. I only want to change columns if a W# is scanned.

  8. #8
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: If entered value starts with "W" Move it.

    I put the following code into a worksheet, I could not paste it here - a SQL error was thrown, but I don't know why
    copy the code into your workbook/worksheet

    should do as I understood you

    cheers,
    Guenter
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-30-2020
    Location
    fresno
    MS-Off Ver
    2017
    Posts
    14

    Re: If entered value starts with "W" Move it.

    Thank You, This is exactly what I was looking for. one small error occurs but it's not a big error. If I rescan an already existing W# and if there is no data underneath it then the code breaks. Thank you for your help!

  10. #10
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: If entered value starts with "W" Move it.

    exchange
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    then the problem will disappear

+ 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 code "if tab name starts with a string, then move these tabs to a new workbook"
    By lynnsong986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2019, 10:55 PM
  2. How to use InStr function to search for a text that starts with "CTF" and ends with "."?
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2014, 06:52 PM
  3. Replies: 1
    Last Post: 08-10-2014, 01:22 PM
  4. Replies: 1
    Last Post: 08-07-2013, 11:09 PM
  5. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  6. Replies: 4
    Last Post: 11-25-2011, 06:59 AM
  7. How do I get "file" tab to click on, it starts with "edit"
    By JMD_Phoenix in forum Excel General
    Replies: 1
    Last Post: 01-22-2006, 10:50 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