how to move the specific text on column A to another column

Carly Lam

New Member
Joined
Jan 6, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello, there are serval question i need help from VBA

1. need to insert one column between column A & B
my answer : Columns("B").Insert

2. if column A cells have text include "up" and "down" will insert to columns C

3. move the last 3 digits of number in column A to column B, and remove the "-" in column A

i hope u can get what i want,,,,,,below picture for your reference, thanks all!!!

Previous
1641529505565.png



Result
1641529538933.png
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Carly,

Welcome to MrExcel!!

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim ws As Worksheet
    Dim i As Long
    Dim strTemp As String
    
    Application.ScreenUpdating = False
    
    Set ws = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing data. Change to suit if necessary.
    ws.Columns("B").Insert
    For i = 1 To ws.Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        If InStr(ws.Range("A" & i), "-") > 0 Then
            strTemp = ws.Range("A" & i)
            ws.Range("A" & i) = Split(strTemp, "-")(0)
            ws.Range("B" & i) = Split(strTemp, "-")(1)
            If InStr(ws.Range("B" & i), " ") > 0 Then
                strTemp = ws.Range("B" & i)
                ws.Range("B" & i) = Split(strTemp, " ")(0)
                ws.Range("C" & i) = Split(strTemp, " ")(1)
            End If
        End If
    Next i
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Hi Carly,

Welcome to MrExcel!!

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim ws As Worksheet
    Dim i As Long
    Dim strTemp As String
   
    Application.ScreenUpdating = False
   
    Set ws = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing data. Change to suit if necessary.
    ws.Columns("B").Insert
    For i = 1 To ws.Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        If InStr(ws.Range("A" & i), "-") > 0 Then
            strTemp = ws.Range("A" & i)
            ws.Range("A" & i) = Split(strTemp, "-")(0)
            ws.Range("B" & i) = Split(strTemp, "-")(1)
            If InStr(ws.Range("B" & i), " ") > 0 Then
                strTemp = ws.Range("B" & i)
                ws.Range("B" & i) = Split(strTemp, " ")(0)
                ws.Range("C" & i) = Split(strTemp, " ")(1)
            End If
        End If
    Next i
   
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
thank you Robert!!!!

i tried and it works!!! thank you very much
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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