Need vba : Extract data after mark , (comma)

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hello all,

perhaps, you can help me how to replace or extract data after mark , (comma) using vba code

like see this :

sample raw after macro
Alam Subur, CV/Komala BudimanAlam Subur
Genteng Garuda Riau Agung, CVGenteng Garuda Riau Agung
Husni, M/Toko Sepatu BataHusni
Indah Jaya, PTIndah Jaya
etc...

<tbody>
</tbody>

for anything for me, thanks in advance...

m.susanto
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
muhammad susanto,

Sample raw data:


Excel 2007
AB
1Alam Subur, CV/Komala Budiman
2Genteng Garuda Riau Agung, CV
3Husni, M/Toko Sepatu Bata
4Indah Jaya, PT
5
Sheet1


After the macro:


Excel 2007
AB
1Alam Subur, CV/Komala BudimanAlam Subur
2Genteng Garuda Riau Agung, CVGenteng Garuda Riau Agung
3Husni, M/Toko Sepatu BataHusni
4Indah Jaya, PTIndah Jaya
5
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub ExtractBeforeComma()
' hiker95, 11/11/2013
' http://www.mrexcel.com/forum/excel-questions/738486-need-visual-basic-applications-extract-data-after-mark-comma.html
Dim a As Variant, b As Variant
Dim i As Long, s
a = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
  If InStr(Trim(a(i, 1)), ",") > 0 Then
    s = Split(a(i, 1), ",")
    b(i, 1) = s(0)
  End If
Next i
Range("B1").Resize(UBound(b, 1), UBound(b, 2)) = b
Columns(2).AutoFit
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ExtractBeforeComma macro.
 
Upvote 0
muhammad susanto,

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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