Macro to look in one column and insert info into another

neilp

Well-known Member
Joined
Jul 5, 2004
Messages
529
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a spreadsheet with a chunk of data.

Could do with a macro that would look in column I, starting at row 2 and place info into Column A in the corresponding row.

Info is as follows:
If it finds 1289 in column I, it needs to put XY40 in column A
If it finds 1060 in column I, it needs to put XY30 in column A
If it finds 1374 or 1128 or 1326 or 1259 or 1375 or 1115 or 1337 or 1331 or 1380 in column I, it needs to put XY20 in column A
Anything else it finds in column I needs to put XY10 in column A

Hope that makes Sense

Thanks in advance

Neil
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try running this on a copy of the data:

Code:
Public Sub FillAFromI()

Dim lastRow As Long
Dim thisRow As Long

lastRow = Cells(Rows.Count, "I").End(xlUp).Row
For thisRow = 2 To lastRow
    Select Case Cells(thisRow, "I").Value
        Case 1289
            Cells(thisRow, "A").Value = "XY40"
        Case 1060
            Cells(thisRow, "A").Value = "XY30"
        Case 1374, 1128, 1326, 1259, 1375, 1115, 1337, 1331, 1380
            Cells(thisRow, "A").Value = "XY20"
        Case Else
            Cells(thisRow, "A").Value = "XY10"
    End Select
Next thisRow

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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