+ Reply to Thread
Results 1 to 7 of 7

Automatically changing cell numbers into names

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2022
    Location
    Belgium
    MS-Off Ver
    latest
    Posts
    9

    Automatically changing cell numbers into names

    I am looking for some help on making a bit of code as I don't know how to do it.

    I have cells for these variables: (so they can be easily edited)
    ID1: 04e42adab35780 (used for Person1: customer)
    ID2: 04944d8a126885 (used for Person2: chief)
    ...

    The code needed would change the ID's from all the data into the persons name (the ones from above) once I click a button


    I already have this code to import data from a different file:
    Sub RFID_Omzetter() ' ' RFID_Omzetter Macro ' RFID cijfers omzetten naar namen ' ' Sneltoets: Ctrl+d ' ' gegevens kopiëren van een werkblad naar werkblad RFID Omzetter vanaf cel A10 Dim wsCopy As Worksheet Dim wsDest As Worksheet Dim lCopyLastRow As Long Dim lDestLastRow As Long Dim ImporteerNaam As String Dim Badge1 As String, badge2 As String ImporteerNaam = [B3].Value Badge1 = [B5].Value badge2 = [B6].Value '0. Open workbook Workbooks.Open "C:\Users\stagiair\Documents\" & ImporteerNaam & "" Set wsCopy = Workbooks(ImporteerNaam).Worksheets(1) 'The last 1 means the first page of the worksheet Set wsDest = Workbooks("RFID omzetter.xlsm").Worksheets("RFID Omzetter") '1. Find last used row in the copy range based on data in column A lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row '2. Find first blank row in the destination range based on data in column A 'Offset property moves down 1 row lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row '3. Clear contents of existing data range wsDest.Range("A10:G" & lDestLastRow).ClearContents '4. Copy & Paste Data wsCopy.Range("A1:G" & lCopyLastRow).Copy _ wsDest.Range("A10") '5. Close workbook Workbooks(ImporteerNaam).Close SaveChanges:=True End Sub
    Attached Files Attached Files
    Last edited by IGDT; 02-24-2022 at 09:42 AM. Reason: solved the problem

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Automatically changing cell numbers into names

    Would you confirm that when there are more people the data currently starting in row 10 simply moves further down and that the formula

    =IFERROR(INDEX($D$5:$D$6,MATCH(F11,$B$5:$B$6,FALSE),1),"")

    in G2 copied down gives you what you want
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    02-16-2022
    Location
    Belgium
    MS-Off Ver
    latest
    Posts
    9

    Re: Automatically changing cell numbers into names

    Quote Originally Posted by Richard Buttrey View Post
    Would you confirm that when there are more people the data currently starting in row 10 simply moves further down and that the formula

    =IFERROR(INDEX($D$5:$D$6,MATCH(F11,$B$5:$B$6,FALSE),1),"")

    in G2 copied down gives you what you want
    The formula you gave has an error somewhere I think.

    But yes, I want to be able to put more people as well, if its to many people then ill just change the A10 to a higher value to start pasting from.

    I was thinking on something like this, but its not working:
    If Range("B6").Value = Range("F11:F21").Value Then
          Range("F11:F21").Value = [D6].Value
        ElseIf Range("B7").Value = Range("F12:F21").Value Then
          Range("F12:F21").Value = [D7].Value
        End If
    Last edited by IGDT; 02-17-2022 at 03:44 AM.

  4. #4
    Registered User
    Join Date
    02-16-2022
    Location
    Belgium
    MS-Off Ver
    latest
    Posts
    9

    Re: Automatically changing cell numbers into names

    So I fixed the code from this reply on myself to this:
        For i = 11 To lDestLastRow + 1
          Set rfidvalue1 = Worksheets(2).Range("B3")
          Set rfidvalue2 = Worksheets(2).Range("B4")
          Set rfidvalue3 = Worksheets(2).Range("B5")
          Set rfidnaam1 = Worksheets(2).Range("C3")
          Set rfidnaam2 = Worksheets(2).Range("C4")
          Set rfidnaam3 = Worksheets(2).Range("C5")
          
          If rfidvalue1.Value = Worksheets(1).Cells(i, 6) Then
            Cells(i, 7).Value = rfidnaam1
          ElseIf rfidvalue2.Value = Worksheets(1).Cells(i, 6) Then
            Cells(i, 7).Value = rfidnaam2
          ElseIf rfidvalue3.Value = Worksheets(1).Cells(i, 6) Then
            Cells(i, 7).Value = rfidnaam3
        
          End If
          
        Next i
    But as you can see, it's a bit sloppy and only works for 3 ids. How would I change it so that I can get up to 100 ids?
    I added the excel file again as I changed some important things
    Attached Files Attached Files

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Automatically changing cell numbers into names

    [QUOTE=IGDT;5636948]The formula you gave has an error somewhere I think.

    Oops, I should have said copy it to G11 and then copy down of course.

    WIth a generalised macro

    Dim lLastNameRow As Long, lFirstSessionRow As Long, llastSessionRow As Long
        lLastNameRow = Blad1.Range("A5").CurrentRegion.Rows.Count + 4
        llastSessionRow = Blad1.Range("B" & Rows.Count).End(xlUp).Row
        lFirstSessionRow = Blad1.Range("A" & lLastNameRow).End(xlDown).Row + 1
        
        Range("G" & lFirstSessionRow & ":G" & llastSessionRow) = "=IFERROR(INDEX($D$5:$D$" & lLastNameRow & ",MATCH(F" & lFirstSessionRow & ",$B$5:$B$" & lLastNameRow & ",FALSE),1),"""")"
        Range("G" & lFirstSessionRow & ":G" & llastSessionRow) = Range("G" & lFirstSessionRow & ":G" & llastSessionRow).Value

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

    Re: Automatically changing cell numbers into names

    If "ID tag" always stars from A5 and gap(blank row(s)) between last "ID tag" and "Session Number" then
    
    Sub test()
        Dim x, r As Range, i As Long
        x = [a5].CurrentRegion.Value
        Set r = Columns(1).Find("Session Number", , , 1)
        If Not r Is Nothing Then
            For i = 1 To UBound(x, 1)
                r.CurrentRegion.Columns("f").Replace x(i, 2), x(i, 4), 1
            Next
        End If
    End Sub

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

    Re: Automatically changing cell numbers into names

    Sub test()
        Dim x, r As Range, i As Long
        x = Sheets("rfid tags").[a1].CurrentRegion.Value
        Set r = Columns(1).Find("Session Number", , , 1)
        If Not r Is Nothing Then
            For i = 3 To UBound(x, 1)
                r.CurrentRegion.Columns("f").Replace x(i, 2), x(i, 4), 1
            Next
        End If
    End Sub

+ 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. Changing names based on another table automatically
    By amirmir in forum Excel General
    Replies: 9
    Last Post: 02-07-2020, 12:39 PM
  2. How to prevent excel from changing UDF names automatically
    By kotnig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2018, 03:53 PM
  3. Changing names to User ID numbers
    By stoudty in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-12-2012, 08:00 AM
  4. Vlookup, Changing names to numbers, and other fun Excel adventures
    By jasbentle in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2012, 08:46 PM
  5. Automatically Changing Numbers to Date
    By Intoxicated-T-F in forum Excel General
    Replies: 4
    Last Post: 12-07-2007, 05:47 PM
  6. Excel Changing Numbers Automatically
    By TomJerzey in forum Excel General
    Replies: 4
    Last Post: 09-19-2005, 10:05 AM
  7. [SOLVED] How do I automatically calculate YTD numbers by changing a date?
    By MDSistah in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-29-2005, 01:06 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