+ Reply to Thread
Results 1 to 6 of 6

VBA swapping rows - text turning to numeric problem

  1. #1
    Registered User
    Join Date
    12-27-2015
    Location
    Iowa, USA
    MS-Off Ver
    2010
    Posts
    83

    VBA swapping rows - text turning to numeric problem

    Hi everyone, hope all are safe.

    I have an app that is essentially a form, where 20 rows hold data regarding employees. Occasionally the user has to remove an employee and move an employee into that row (and associated data). So I decided to put 20 radio buttons representing the "From" row and 20 radios representing the "To" row, so the user could simply check one from each and the code would move the records from the first row into the second row, then remove the records from which it came. Cells A30 and B30 provide the row numbers. The basic code looks like this (but there are actually around 140 associated fields)...

    HTML Code: 
    The problem I'm having is G and H are text fields, while the rest are numeric. But, when it copies to the new row, both G and H show the value of F. H is a select box, but still text. I've searched online for this but I keep getting the standard answers about making a cell equal another one. This issue seems to be a one-off. I would have searched this forum, but honestly expect to find similar answers and not get resolution. So, I'm here with a couple questions.

    Why is my text transfer not pasting text, but grabbing the last value to the left? Does that mean my variable isn't being replaced with the text and therefore continuing the most recent value? Seems reasonable, but what's the fix.

    Also, you'll immediately see I'm doing one field at a time. Is there a way to apply this to a range?

    Any consideration is appreciated. Have a great weekend all. Be safe out there.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,278

    Re: VBA swapping rows - text turning to numeric problem

    sorry for possible misapprehension
    was it about this ?
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-27-2015
    Location
    Iowa, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: VBA swapping rows - text turning to numeric problem

    Thank you for the reply.

    It doesn't seem to do what I need. With your illustration(workbook), I would pick the values of A30 and B30 via radio buttons. When invoking the "run" with a button, it would transfer the data from row number found in A30 and transfer to the row number found in B30. The code I have does this. However, and again using your illustration, if for example I choose to move row 2 to row 3, the text in column's G and H populate with the numeric value found in column F. I don't understand why it's doing this. My fields are formatted correctly. I thought I declared the variable correctly, and even declared another variable to account for text. I don't know enough about VBA to say, but it seems that when the text variable is capturing the value in the cell, it can't read it and decides to keep the previous value and paste that instead. Still struggling.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: VBA swapping rows - text turning to numeric problem

    Quote Originally Posted by LewisBosworth View Post
    The problem I'm having is G and H are text fields, while the rest are numeric. But, when it copies to the new row, both G and H show the value of F.
    Because the variable
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-27-2015
    Location
    Iowa, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: VBA swapping rows - text turning to numeric problem

    Thank you jindon, for taking a look at this. I knew it was something simple. You solved the issue! Be well and have a great day!

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: VBA swapping rows - text turning to numeric problem

    You are welcome and thanks for the rep.

    I would go like this, so that you don't need to care about the data type of each cell.
    Please Login or Register  to view this content.

+ 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. Problem with VLookup and Index Match on mixed Text and Numeric codes
    By Vaslo in forum Excel Formulas & Functions
    Replies: 28
    Last Post: 12-17-2013, 12:54 PM
  2. swapping rows
    By lgbingham in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-20-2013, 04:40 PM
  3. swapping colums and rows
    By STANSBURY in forum Excel General
    Replies: 7
    Last Post: 11-05-2012, 05:24 AM
  4. Columns to rows (swapping X & Y axis)
    By ellie4679 in forum Excel General
    Replies: 2
    Last Post: 11-21-2007, 05:00 AM
  5. Swapping rows
    By girish_mu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2006, 02:59 PM
  6. [SOLVED] Swapping rows and columns
    By Dorn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-11-2005, 05:10 PM
  7. Delete rows with numeric values, leave rows with text
    By GSpline in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2005, 08:05 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