Categorize data in the right column

catae

New Member
Joined
May 5, 2023
Messages
5
Office Version
  1. 2019
Platform
  1. MacOS
I have a spreadsheet with an ID (column A) and corresponding tags in 4 columns (B,C,D,E). The problem is those tags are mixed, and not all of them belong to the column they are right now.
For example: B6 which right now is in the category "Channel" in column B, really belongs to column D in the "vertical" category.
C3 which right now is in the category "Feeling" in column C, really belongs to column B in the "Channel" category.
Captura de Pantalla 2023-05-05 a la(s) 2.20.52 p. m..png


I have the right categorization in another part of the spreansheet:

Captura de Pantalla 2023-05-05 a la(s) 2.24.38 p. m..png


How can i organize it, so that each column has the right information? Also, sometimes there is no data in every column.

Please help!! I've searched and i haven't been able to come up with anything

Thank you so much in advance :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
you have 5 categories at the top and 4 at the bottom? the top is Englisth words, the bottom Spanish? Please correct.
Also, please post a mini worksheet using the xl2bb add in (link below). You are asking the forum to EXACTLY recreate your worksheet, that takes time and error and typos can cause problems and make valid solutions look invalid.
 
Upvote 0
Hello @catae
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

I think you missed column F.
If you have your data like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2comprarfacebookneutralsolicitudIGpositivocréditocomentariostendencia
41_3comentariospositivoTik Tokneutralpublicarsolicitudblog
51_4blogcomentariosfacebookpositivofacsubastaeducativo
61_5arriendofacebookneutralsolicitudsubsidiofree press
71_6comentariosneutralpublicarcomprar
ids (2)


The result will be like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2facebookneutralcomprarsolicitudIGpositivocréditocomentariostendencia
41_3positivocomentariosTik Tokneutralpublicarsolicitudblog
51_4facebookpositivocomentariosblogfacsubastaeducativo
61_5facebookneutralarriendosolicitudsubsidiofree press
71_6neutralpublicarcomentarioscomprar
ids (2)


Test the following Macro:
VBA Code:
Sub categorize()
  Dim rng1 As Range, rng2 As Range, f As Range
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, col As Long
 
  Set rng1 = Range("B2:F" & Range("A" & Rows.Count).End(3).Row)
  Set rng2 = Range("G:K")
  a = rng1.Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  col = rng2.Cells(1).Column - 1
 
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        Set f = rng2.Find(a(i, j), , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          b(i, f.Column - col) = a(i, j)
        End If
      End If
    Next
  Next
 
  rng1.Value = b
End Sub

HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (categorize) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Note XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Last edited:
Upvote 0
you have 5 categories at the top and 4 at the bottom? the top is Englisth words, the bottom Spanish? Please correct.
Also, please post a mini worksheet using the xl2bb add in (link below). You are asking the forum to EXACTLY recreate your worksheet, that takes time and error and typos can cause problems and make valid solutions look invalid.
Thank for your responde, unfortunately i cant seem to find add ins in my excel. I've seen videos and read stuff on how to find it, but it doesn't show up in mine :(
 
Upvote 0
Hello @catae
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

I think you missed column F.
If you have your data like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2comprarfacebookneutralsolicitudIGpositivocréditocomentariostendencia
41_3comentariospositivoTik Tokneutralpublicarsolicitudblog
51_4blogcomentariosfacebookpositivofacsubastaeducativo
61_5arriendofacebookneutralsolicitudsubsidiofree press
71_6comentariosneutralpublicarcomprar
ids (2)


The result will be like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2facebookneutralcomprarsolicitudIGpositivocréditocomentariostendencia
41_3positivocomentariosTik Tokneutralpublicarsolicitudblog
51_4facebookpositivocomentariosblogfacsubastaeducativo
61_5facebookneutralarriendosolicitudsubsidiofree press
71_6neutralpublicarcomentarioscomprar
ids (2)


Test the following Macro:
VBA Code:
Sub categorize()
  Dim rng1 As Range, rng2 As Range, f As Range
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, col As Long
 
  Set rng1 = Range("B2:F" & Range("A" & Rows.Count).End(3).Row)
  Set rng2 = Range("G:K")
  a = rng1.Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  col = rng2.Cells(1).Column - 1
 
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        Set f = rng2.Find(a(i, j), , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          b(i, f.Column - col) = a(i, j)
        End If
      End If
    Next
  Next
 
  rng1.Value = b
End Sub

HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (categorize) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Note XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
Oh m y god Dante, thank you soooo much!! Indeed in the rush to post the thread, i forgot to translate one of the charts and also add the F column, my bad!!

I wanted to give the sample with XL2BB, i downloaded it, but the add ins option doesn't show up in my excel, i dont know why. Maybe the company's admin dissabeled it for security reasons, i don't know.

I'll definitely will try your macro, i'm not very good at them but i'll try to understand it and learn.

Thank you so much again!!!
 
Upvote 0
Hello @catae
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

I think you missed column F.
If you have your data like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2comprarfacebookneutralsolicitudIGpositivocréditocomentariostendencia
41_3comentariospositivoTik Tokneutralpublicarsolicitudblog
51_4blogcomentariosfacebookpositivofacsubastaeducativo
61_5arriendofacebookneutralsolicitudsubsidiofree press
71_6comentariosneutralpublicarcomprar
ids (2)


The result will be like this:
Dante Amor
ABCDEFGHIJK
1IDChannelFeelingVerticalTypePostCanalPolaridadTransacciónTipo de mensajeTipo de post
21_1facebookneutralpublicarsolicitudfacebookNegativoarriendoasesoríamemes
31_2facebookneutralcomprarsolicitudIGpositivocréditocomentariostendencia
41_3positivocomentariosTik Tokneutralpublicarsolicitudblog
51_4facebookpositivocomentariosblogfacsubastaeducativo
61_5facebookneutralarriendosolicitudsubsidiofree press
71_6neutralpublicarcomentarioscomprar
ids (2)


Test the following Macro:
VBA Code:
Sub categorize()
  Dim rng1 As Range, rng2 As Range, f As Range
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, col As Long
 
  Set rng1 = Range("B2:F" & Range("A" & Rows.Count).End(3).Row)
  Set rng2 = Range("G:K")
  a = rng1.Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  col = rng2.Cells(1).Column - 1
 
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        Set f = rng2.Find(a(i, j), , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          b(i, f.Column - col) = a(i, j)
        End If
      End If
    Next
  Next
 
  rng1.Value = b
End Sub

HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (categorize) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Note XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
Dante, i followed your instructions and after i run the macro, this shows up...i don't know what to do :(

Captura de Pantalla 2023-05-05 a la(s) 4.38.06 p. m..png
 
Upvote 0
Without the data you are running the macro with I can only guess.

Start by telling me what error message you get?

What data do you have in column A?
As per your example, in column A you should have the id.

Do you have errors in your cells, something like #N/A, #DIV/0, #NAME, #REF, etc?

Try the macro with my examples.
Copy the data from the minisheet and paste it into your sheet.


If you have errors in your cells try this macro:
VBA Code:
Sub categorize()
  Dim rng1 As Range, rng2 As Range, f As Range
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, col As Long
  
  Set rng1 = Range("B2:F" & Range("A" & Rows.Count).End(3).Row)
  Set rng2 = Range("G:K")
  a = rng1.Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  
  col = rng2.Cells(1).Column - 1
  
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If Not IsError(a(i, j)) Then
        If a(i, j) <> "" Then
          Set f = rng2.Find(a(i, j), , xlValues, xlWhole, , , False)
          If Not f Is Nothing Then
            b(i, f.Column - col) = a(i, j)
          End If
        End If
      End If
    Next
  Next
  
  rng1.Value = b
End Sub

If you're having trouble, come back here and tell us what's wrong and what data you're testing with. If you couldn't add the XL2BB tool then share your file.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

😅
 
Upvote 0
Without the data you are running the macro with I can only guess.

Start by telling me what error message you get?

What data do you have in column A?
As per your example, in column A you should have the id.

Do you have errors in your cells, something like #N/A, #DIV/0, #NAME, #REF, etc?

Try the macro with my examples.
Copy the data from the minisheet and paste it into your sheet.


If you have errors in your cells try this macro:
VBA Code:
Sub categorize()
  Dim rng1 As Range, rng2 As Range, f As Range
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, col As Long
 
  Set rng1 = Range("B2:F" & Range("A" & Rows.Count).End(3).Row)
  Set rng2 = Range("G:K")
  a = rng1.Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
 
  col = rng2.Cells(1).Column - 1
 
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If Not IsError(a(i, j)) Then
        If a(i, j) <> "" Then
          Set f = rng2.Find(a(i, j), , xlValues, xlWhole, , , False)
          If Not f Is Nothing Then
            b(i, f.Column - col) = a(i, j)
          End If
        End If
      End If
    Next
  Next
 
  rng1.Value = b
End Sub

If you're having trouble, come back here and tell us what's wrong and what data you're testing with. If you couldn't add the XL2BB tool then share your file.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

😅
This one worked perectly, THANK YOUUU!!! I didn't see any errors, buy maybe there were and i didn't catch them because this new macro worked beautifullyyyyy... i can't thank you enough. I'll study the macro and see if i can understand what you did and learn :). Have a great day!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,683
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top