Need data arranged into columns when certain value is seen

NoWhiteFlags

New Member
Joined
Oct 2, 2015
Messages
2
I have many items with bar codes on carts which also have bar codes. Every once in a while, I use a bar code scanner to scan what is on all of the carts. When I do this, the data is input in excel looking like this:

B
T1152567857
T1134567846
T1435678935
T1164536223
C
T1678245534
T5674839298
T6543212387
D
T1154637276
T1154332256
A
T1189274434
T1154987621
T1152590876

And so forth. The letters "B,C,D, A" are the carts and the numbers beginning with T are the items on the carts. There are also many carts (doesn't end at cart D). I would like the data to be arranged so that each time a new cart letter is scanned, it moves to a new column, instead of being a long stream of data in column A. Also, if possible, it would be nice if the carts could be arranged in order so that cart A and its contents would be in column A, cart B in column B, and so forth. Not sure if it makes it easier or not but I could also scan the items into sheet two and have them arranged in sheet 1 if that would help. I am not familiar with macros at all so any help would be appreciated. Thanks!
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here is my solution.
Every time you scan using bar code scanner it will enter it into a cell and either you will hit enter or scanner will.
This will make your selection change to the cell directly below the cell in which information is entered.
Now I am thinking that you will have all your carts marked with excel column name.
So, when you run out from A to Z next cart will be AA to AZ and so on.
I am differentiating between cart and item by the length of the barcode.
Excel has column name in 3 digits only and your items name is larger than 3 digit.
Thus if the value that was entered has character length of 3 digits or less, I am deleting that entry.
After that, what I am trying to do is move you to the next available spot in the column that was just entered.
So incase if you have already scanned some items on a cart and do something else and come back you can just start adding at the end of what is already there.
If I wouldn't have done that than it would have overwritten your previous work.

I am assuming you will never have cart name more than XFD. This gives you 16384 cart name options.
I am also assuming that you will not have any item that has a barcode of 3 digits or less.
In other words if anything has a barcode of 3 digits or less it is a cart and its name is less than XFD.

Enter this code in your workbook object.


Code:
Option Explicit


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


Dim Pc!, Pr!, s$, l!, R!


Pc = ActiveCell.Column
Pr = ActiveCell.Row - 1
s = Cells(Pr, Pc).Value
l = Len(s)
If l = 0 Then Exit Sub


If l < 4 Then
    Cells(Pr, Pc).Clear
    Cells(1, s).Select
    R = Range(s & Rows.Count).End(xlUp).Row
    If R <> 1 Then
        ActiveCell.Offset(R, 0).Select
    End If
End If


End Sub
 
Last edited:
Upvote 0
Click alt key and F11 key together
That will bring you to VBA

Now double click on ThisWorkbook
Paste the code that I have typed up for you above.
Save it and follow the instructions in the previous post.

I have attached a picture of how your VBA should look like.

VBA.png
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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