Cell Value based on another column

Neveidas

New Member
Joined
Oct 6, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm having issues with this
Book1.xlsm
AB
1AbrreviationTransport
2BusBus.inc
3Bus.inc
4Bus.inc
5Bus.inc
6Bus.inc
7Bus.inc
8CarCar co.
9Car co.
10Car co.
11Car co.
12Car co.
13MotorbikeMotorcycle ptd ltd
14Motorcycle ptd ltd
15Motorcycle ptd ltd
16Motorcycle ptd ltd
17Motorcycle ptd ltd
18Motorcycle ptd ltd
19BicycleBicycle ltd
20Bicycle ltd
21Bicycle ltd
22Bicycle ltd
23Bicycle ltd
24Bicycle ltd
25Bicycle ltd
Sheet3


I'm trying to fill column A with abbreviations of Column B and it is til the last filled row in B,

VBA Code:
Sub EcomClass()

Application.ScreenUpdating = False
Dim ws As Worksheet
Dim i As Long, l As Long
Dim r As Range, rr As Range
    
Set ws = ThisWorkbook.Sheets("sheet3")

    i = ws.Range("B" & Rows.Count).End(xlUp).Row
    Set r = ws.Range("A2:A" & i)
        
       For Each rr In r
        If Cells(i, 2).Value = "Car Co." Then
        r.Value = "Car"
        ElseIf Cells(i, 2).Value = "Bus.inc" Then
        r.Value = "Bus"
        
        End If
        Next
        
    Set ws = Nothing
    Set r = Nothing
    
    
Application.ScreenUpdating = True

End Sub

I tried doing this but it doesn't return any results at all, can anyone help me with this? thank you in advance~
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Is it are you looking for?

VBA Code:
Sub EcomClass()

Application.ScreenUpdating = False
Dim ws As Worksheet
Dim i As Long, j As Long
Dim r As String
    
Set ws = ThisWorkbook.Sheets("sheet3")
    j = ws.Range("B" & Rows.Count).End(xlUp).Row
       
       For i = 2 To j
       r = Cells(i, 2).Value
        If Left(r, 2) = "Bu" Then
        Cells(i, 1).Value = "Bus"
            ElseIf Left(r, 2) = "Ca" Then
            Cells(i, 1).Value = "Car"
                ElseIf Left(r, 2) = "Mo" Then
                Cells(i, 1).Value = "Motobike"
                    ElseIf Left(r, 2) = "Bi" Then
                    Cells(i, 1).Value = "Bicycle"
        End If
       Next
            
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Is it are you looking for?

VBA Code:
Sub EcomClass()

Application.ScreenUpdating = False
Dim ws As Worksheet
Dim i As Long, j As Long
Dim r As String
   
Set ws = ThisWorkbook.Sheets("sheet3")
    j = ws.Range("B" & Rows.Count).End(xlUp).Row
      
       For i = 2 To j
       r = Cells(i, 2).Value
        If Left(r, 2) = "Bu" Then
        Cells(i, 1).Value = "Bus"
            ElseIf Left(r, 2) = "Ca" Then
            Cells(i, 1).Value = "Car"
                ElseIf Left(r, 2) = "Mo" Then
                Cells(i, 1).Value = "Motobike"
                    ElseIf Left(r, 2) = "Bi" Then
                    Cells(i, 1).Value = "Bicycle"
        End If
       Next
           
Application.ScreenUpdating = True

End Sub
Yes, this is what I am looking for, i could use the same codes for this right?

Book1.xlsm
AB
2CONVENANT LOGISTICS CO LTD
3CONVENANT LOGISTICS CO LTD
4CONVENANT LOGISTICS CO LTD
5CONVENANT LOGISTICS CO LTD
6CONVENANT LOGISTICS CO LTD
7CONVENANT LOGISTICS CO LTD
8CONVENANT LOGISTICS CO LTD
9HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
10HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
11HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
12HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
13HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
14HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
15HONGKONG WEIBIN TECHNOLOGY NETWORK LIMITED
16Jet International Logistics
17Jet International Logistics
18Jet International Logistics
19Jet International Logistics
20Jet International Logistics
21Jet International Logistics
22Jet International Logistics
23Jet International Logistics
Sheet3


Or is there any changes to the VBA?
 
Upvote 0
How many enterprises does it have? If 3, it is OK. If more, try to create lookup table with list of unique enterprises
 
Upvote 0
How many enterprises does it have? If 3, it is OK. If more, try to create lookup table with list of unique enterprises
There's more than 3 actually,

How do I go about creating a lookup table for them?
 
Upvote 0
Store lookup table somewhere, then using VLOOKUP to get data. No code required.
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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