Can some one help to write a piece of vba code

msh250

New Member
Joined
Jun 14, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am new to VBA and would need help to write a piece of code for the requirements below:
i have a spreadsheet with 1000's of data

From the data in the column “N”, for each line:
  • Copy-paste all the objects starting with “L-“ into a new column named “Location Type”
  • Copy-paste all the objects starting with “T-Special “ into a new column named “Special Requirement”
  • Copy-paste all the objects starting with “S-Echo” and the object “S-Zoom capable” into a new column named “Online Delivery”
  • Copy-paste all the remaining objects into a new column named “Location attributes”
 
For fast help, could you attach a mini sheet via XL2BB tool?
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
For fast help, could you attach a mini sheet via XL2BB tool?
Book1
MN
1Scheduled Finish as end timeName
211:00L-Analysis
315:00L-CTA teach
415:00L-CTA Analysis
515:00L-MTV Teach
615:00AM-OW;L-CTA Teach
713:00S-EchoWLV;L-CTA Analysis
813:00S-EchoWLV;L-CTA Teach
913:00S-EchoWLV;L-CTA Teaching
1013:00L-CTA Analysis;AV-LOWER
1113:00L-CTA Analysis;AV-LOWER
1213:00L-CTA Analysis;AV-LOWER
1313:00L-CTA Analysis;AV-LOWER
1413:00L-CTA Analysis;AV-LOWER
1516:00L-CTA Teach;S-Moveable;S-Alter
1612:00S-EchoWLV;S-Echo Live;L-CTA Analysis
1712:00S-EchoWLV;S-Echo Live;L-CTA Analysis
1812:00S-EchoWLV;S-Echo Live;L-CTA Analysis
1912:00S-EchoWLV;S-Echo Live;L-CTA Analysis
2018:00@Zoom
2118:00@Zoom
2218:00@Zoom
2316:00L-Analysis
2416:00L-Analysis
2516:00L-Analysis
2612:00AM-OW;L-CTA Teach
2712:00AM-OW;L-CTA Teach
2812:00AM-OW;L-CTA Teach
2912:00AM-OW;L-CTA Teach
3015:30S-Zoom room -
3112:00AV-MEDIUM
3210:00L-Analysis
3310:00L-Analysis
3414:00AM-OW;L-CTA Teach
3514:00AM-OW;L-CTA Teach
3614:00AM-OW;L-CTA Teach
3710:00S-EchoWLV;S-Echo Live;L-CTA Teach;T-Special Medium
3810:00S-EchoWLV;S-Echo Live;L-CTA Teach;T-Special Medium
3910:00S-EchoWLV;S-Echo Live;L-CTA Teach;T-Special Medium
Sheet1
 
Upvote 0
try again.
For some cells has multi values those belong to same column, like this: S-EchoXXX;S-EchoYYY, they will be put in same column, separated by semicolon .
VBA Code:
Option Explicit
Sub Distribute()
Dim lr&, i&, j&, rng, arr(), s, st1 As String, st2 As String, st3 As String, st4 As String
lr = Cells(Rows.Count, "N").End(xlUp).Row
rng = Range("N2:N" & lr).Value ' assume data starts from N2
Range("O1:R1").Value = Array("Location Type", "Special Requirement", "Online Delivery", "Location attributes")
ReDim arr(1 To lr - 1, 1 To 4)
For i = 1 To lr - 1
    st1 = "": st2 = "": st3 = "": st4 = ""
    s = Split(rng(i, 1), ";")
    For j = 0 To UBound(s)
        If UCase(s(j)) Like "L-*" Then
            st1 = st1 & ";" & s(j): arr(i, 1) = Right(st1, Len(st1) - 1)
        ElseIf UCase(s(j)) Like "T-SPECIAL*" Then
            st2 = st2 & ";" & s(j): arr(i, 2) = Right(st2, Len(st2) - 1)
        ElseIf UCase(s(j)) Like "S-ECHO*" Or UCase(s(j)) Like "S-ZOOM*" Then
            st3 = st3 & ";" & s(j): arr(i, 3) = Right(st3, Len(st3) - 1)
        Else
            st4 = st4 & ";" & s(j): arr(i, 4) = Right(st4, Len(st4) - 1)
        End If
    Next
Next
Range("O2").Resize(UBound(arr), 4).Value = arr
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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