+ Reply to Thread
Results 1 to 5 of 5

How uniformize diferent types of Data (SOLVED)

  1. #1
    Registered User
    Join Date
    12-05-2019
    Location
    Lisbon
    MS-Off Ver
    365 ProPlus
    Posts
    5

    How uniformize diferent types of Data (SOLVED)

    Hello Gurus. This is my first time working on a macro.

    I need to match data from two diferent tables in excel, and unfortanely, the data in the two tables isn't treated in the same way.

    For example, in one table I have 2K2 (2,2*10^3), and on the other table I have 2,2K (also 2,2*10^3). As you can see, the value of the data is the same, but being that it isn't treated the same way, it doesnt't match. So I was thinking about making a cycle that would run all of both tables, and transform the data so it would be the same. For example 2K2 and 2,2K would become 2,2*10^3. Or 2K2 would become 2,2K.
    (Example of the values Below)

    Table 1 |Table2
    4,300K |4K3
    39,00C |39C
    36,00P | 36P


    Do you have any advice? I spent all day trying to find examples of how through cycle through a string, and if some condition was met, (for example, if my char was K) it would transform it to the value i wanted (10^3). But I feel like I'm way out of my league here.

    Maybe this is very simple problem to solved, but I'm have no experience in programming macros. I appologize in advance if I'm breaking some forum rule.

    Thanks for the Help.
    Last edited by lquesado; 12-09-2019 at 04:38 AM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: How uniformize diferent types of Data

    Is the text indicator always "K" or do you also have values with "M" or "m" or "c" or other SI or similar prefixes?

    If it's always K and it always means *10^3, I would go with something like:
    1) A substitute function to get rid of the K. For table 1, substitute "K" with "" SUBSTITUTE(A2,"K",""). For table 2, substitute "K" with "," SUBSTITUTE(B2,"K",",")
    2) Then mutliply the resulting number as text by 1000 (Excel will automatically convert to a number. In both cases =SUBSTITUTE(...)*1000

    Will that work?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    12-05-2019
    Location
    Lisbon
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: How uniformize diferent types of Data

    Hello MrShorty.

    Thank You For your help.

    The text Indicator isn't always K, it could also be U, N, or P (10^-6 ; 10^-9; 10^-12).

    What maybe would work would be a cycle runing the tables, a Cycle (or something to read the value) and 3 If Conditions. On the First Table IF the value as a K, does SUBSTITUTE(A2,"K","") and multiplies by 1000. On the Second IF, IF the value as a U, does SUBSTITUTE(A2,"C","") and multiplies by 10^-6 etc.
    Do you think that would work? Is there a simpler way? How do I make a loop that reads the caracters in the value (loop to read a string).

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: How uniformize diferent types of Data

    Yes, I think that sort of strategy would work.

    I do not know if there is a simpler way. At the same time, my mentor taught me to program within my abilities rather than seek out procedures that I did not understand -- even if the way I understand is less efficient than what a more experienced programmer would do. Somewhere in this is deciding how difficult it is to learn new coding strategies against how much is lost doing it how I know.

    I had not noticed earlier, but your question seems to assume that you will do this in VBA rather than using Excel's worksheet functions. I generally prefer worksheet functions myself over VBA, so I would ask if you are required to use VBA, or if you prefer VBA, or if you are interested in a worksheet formula approach.

    Overview of a VBA approach: 1) Like you suggest use a block IF or a Select Case structure to detect those specific characters and determine the multiplier, followed (2) by a Replace() function that replaces the text with your decimal separator, followed by (3) multiplying the number by the multiplier. Step (4) is to put all of that inside of your desired loop structure.

    A worksheet formula approach would do all of the same steps: 1) Nested IF() or a lookup function to detect the characters and return the appropriate multiplier followed (2) by a SUBSTITUTE()*multiplier step.

    I guess at this point, you need to decide which programming language you prefer to use for this, and then we can help

  5. #5
    Registered User
    Join Date
    12-05-2019
    Location
    Lisbon
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: How uniformize diferent types of Data

    Mr Shorty I've managed to solve the problem with the help of a informatic engineer friend of mine.

    Basicaly, the code runes the Column 1 while the value is diferente from empty. Then it checks if the string has any K.

    If InStr(Cells(i, 1).Value, "K") > 0 Then

    And Then replaces it with empty and multiplies for the correct value (in case of K, 1000) and so one for the rest of the column.

    At least for now, It seems works on both columns, the ones with 1,200K and the ones with 1K2.

    Below is an example of the code


    Private Sub CommandButton1_Click()
    Dim i As Integer
    i = 1

    Do While Cells(i, 1).Value <> ""

    If InStr(Cells(i, 1).Value, "K") > 0 Then
    Cells(i, 1).Value = Replace(Cells(i, 1).Value, "K", "")
    Cells(i, 1).Value = Cells(i, 1).Value * 1000
    ElseIf InStr(Cells(i, 1).Value, "M") > 0 Then
    Cells(i, 1).Value = Replace(Cells(i, 1).Value, "M", "")
    Cells(i, 1).Value = Cells(i, 1).Value * 1000000
    End If


    i = i + 1
    Loop
    End Sub


    Thank you the help and attention.

+ 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. use same Userform to get data from diferent cell
    By Henrik-Chr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-10-2018, 12:02 PM
  2. Macro to copu split data into diferent column
    By dobracik in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2015, 09:24 AM
  3. [SOLVED] Removing data from 2 diferent worksheets with the same macro???
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2014, 03:35 PM
  4. [SOLVED] sort data and move it to diferent sheets
    By Ashrak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2013, 11:18 AM
  5. from value in combo box find data in 2 diferent sheets
    By cdafonseca in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2013, 12:43 PM
  6. Replies: 2
    Last Post: 07-03-2012, 07:16 PM
  7. Get data from diferent workbooks to a single workbook
    By clixo in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 10-26-2010, 12:51 PM

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