+ Reply to Thread
Results 1 to 9 of 9

Numbers in cells not recognized when using InputBox to copy and paste rows

  1. #1
    Registered User
    Join Date
    04-22-2013
    Location
    In the lab...
    MS-Off Ver
    Excel 2010
    Posts
    12

    Numbers in cells not recognized when using InputBox to copy and paste rows

    Greetings,

    I have code to cut-and-paste rows to another sheet based on the value in the first column matching the InputBox entry. It was adapted from code that searched for a word in the first column, and if I change what I have below to "Dim Number as String" and change the InputBox data type to 2, it works perfectly for words. Unfortunately, I need it to look for a number in the first column, but it doesn't seem to see the numbers (either in number, general, or text format). I need it to do two things:

    1) Copy and paste the rows beginning with the number (the number that's in column A of Sheet1) entered in the InputBox onto Sheet2, and only take the rows beginning with that exact number (in other words, only the row beginning with, say, 2 - not 22, 12, 122, etc.).

    2) Delete whatever was in Sheet2 from the previous query before pasting the new set of rows.

    Thank you in advance for your assistance; my code is as follows:

    Please Login or Register  to view this content.
    Nikolette

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Try this out, run it from sheet 1
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-22-2013
    Location
    In the lab...
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Thanks so much, Dave - it works beautifully! The only trouble I'm having is that it pulls over everything that contains the number I've entered - for example, if I enter "3", it copies and pastes the rows that start with "3" and the rows that have 3 in them, such as "39", "43", etc. Is there a way to make it pull the rows with exactly the number entered (not simply containing the number entered)?

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    This works for me.

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    It shouldn't be pulling 43, because 3 is not the start number.

    I will continue on to just find just the number 3 or what ever number you put in the input box.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Will the cell only have the string that is in the inputbox or will there be other strings attached?

  7. #7
    Registered User
    Join Date
    04-22-2013
    Location
    In the lab...
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Dave: My mistake - you are correct; it pulls over all numbers that start with that number (43 was a bad example). The only thing in the cell in column A is a number, currently anything from 1 to 250 (there will be more entries in the future).

    JapanDave: Thanks! The problem of it pulling over rows starting with the exact number (only 3, for ex., instead of 3, 39, and 3-whatever) is solved :-)

    I've added in the line to delete the contents of Sheet2 and it works like a charm - thank you so much to both of you for your help!

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Well I guess this should work then, no loops required.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-22-2013
    Location
    In the lab...
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Numbers in cells not recognized when using InputBox to copy and paste rows

    Thank you, Dave - I appreciate it greatly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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