Need help creating a macro

lantros79

New Member
Joined
Jul 4, 2017
Messages
3
Hi Everyone! I need help creating a macro that does the following:

  • Copy column I and paste the values there
  • In column I, If there is a space before “OZ”, “PK”, or “CT”, delete it
  • If the W column has “OG” in it, type “OG” at the beginning of the cells in column F
Thanks for your help!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello,

does this work as expected?

Code:
Sub COLUMN_I()
    Application.ScreenUpdating = False
    With Columns(9)
        .Copy
        .Range("I1").PasteSpecial (xlPasteValues)
        .Replace What:=" OZ", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" PK", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" CT", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
    End With
    For MY_ROWS = 1 To Range("I" & Rows.Count).End(xlUp).Row
        If Range("W" & MY_ROWS).Value = "OG" Then
            Range("F" & MY_ROWS).Value = "OG" & Range("F" & MY_ROWS).Value
        End If
    Next MY_ROWS
    Application.ScreenUpdating = False
End Sub
 
Last edited:
Upvote 0
Hi, thanks for the awesome quick response! Everything worked except the "OG" going to the beginning of the cell in column F. Basically, if "OG if anywhere in column W, and column F has "TEST" in it, I want that cell in column F to read:
OG TEST

Sorry, I wasn't super clear on that one :)

Hello,

does this work as expected?

Code:
Sub COLUMN_I()
    Application.ScreenUpdating = False
    With Columns(9)
        .Copy
        .Range("I1").PasteSpecial (xlPasteValues)
        .Replace What:=" OZ", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" PK", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" CT", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
    End With
    For MY_ROWS = 1 To Range("I" & Rows.Count).End(xlUp).Row
        If Range("W" & MY_ROWS).Value = "OG" Then
            Range("F" & MY_ROWS).Value = "OG" & Range("F" & MY_ROWS).Value
        End If
    Next MY_ROWS
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
Hello,

Code:
Sub COLUMN_I()
    Application.ScreenUpdating = False
    With Columns(9)
        .Copy
        .Range("I1").PasteSpecial (xlPasteValues)
        .Replace What:=" OZ", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" PK", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" CT", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
    End With
    For MY_ROWS = 1 To Range("I" & Rows.Count).End(xlUp).Row
        If Range("W" & MY_ROWS).Value Like "*OG*" Then
            Range("F" & MY_ROWS).Value = "OG " & Range("F" & MY_ROWS).Value
        End If
    Next MY_ROWS
    Application.ScreenUpdating = False
End Sub

this will find OG anywhere in column W ie, "OG", "COG", "COGS", "OGS" and will add OG to columns F.
 
Last edited:
Upvote 0
Awesome! This works great Thank you, have a great day!


Hello,

Code:
Sub COLUMN_I()
    Application.ScreenUpdating = False
    With Columns(9)
        .Copy
        .Range("I1").PasteSpecial (xlPasteValues)
        .Replace What:=" OZ", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" PK", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        .Replace What:=" CT", Replacement:="OZ", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
    End With
    For MY_ROWS = 1 To Range("I" & Rows.Count).End(xlUp).Row
        If Range("W" & MY_ROWS).Value Like "*OG*" Then
            Range("F" & MY_ROWS).Value = "OG " & Range("F" & MY_ROWS).Value
        End If
    Next MY_ROWS
    Application.ScreenUpdating = False
End Sub

this will find OG anywhere in column W ie, "OG", "COG", "COGS", "OGS" and will add OG to columns F.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,616
Members
452,661
Latest member
Nonhle

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