Find and paste into a different column based on a table

Silky0

New Member
Joined
Mar 8, 2022
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
I am trying to create a macro that searches a table on the "names" tab in the table called Names. The Names table is a list of company names that should be consolidated (Apple, LLC, Apple, Inc, iPhone, LLC, etc.)

The names are in column A, I want to hardcode the name override in column B, as it's already a slow file. The list goes down to row 1015 at the moment. A recording looks like the below.

Thanks for any help.

Sub Macro2()

Range("B16").Select
ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Names,2,FALSE),"""")"
Selection.Copy
Range("A16").Select
Selection.End(xlDown).Select
Range("B1015").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range("B16").Select
Application.CutCopyMode = False
Calculate
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
bump. thanks in advance for any help cleaning this up.
 
Upvote 0
Welcome to the Forum.

Is your code working now, but the problem is that it is just to slow? Or does it not work properly?

I think it would be very beneficial to us if you could show us a small sample of what your data looks like along with your expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Thank you for the response. See below. Adjusted the macro for the sample that I am posting.

To answer your question, the macro does work, but it is slow and not very dynamic - I am using 9 rows here, not the ~200 rows in this example. The rest of the file is already slow, so I am trying to keep this as a macro to not slow down the file even further.

Column C is meant to be a name override for all the name permutations of a company name, with the ability for manual input as some names will not be in the table. I have had to adjust column D formula from isblank() but would prefer to avoid that, if possible.

Sub Macro1()
Range("C6").Select
ActiveCell.FormulaR1C1 = "=+IFERROR(VLOOKUP(RC[-1],Names,2,FALSE),"""")"
Selection.Copy
Range("B6").Select
Selection.End(xlDown).Select
Range("C231").Select
Range(Selection, Selection.End(xlUp)).Select
Range("C6:C231").Select
Range("C231").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Calculate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

Book1.xlsm
BCDEFGH
3Override Count
47
5Company NameName OverrideLive NameAlternative NamesCompany Name
6AppleAppleAppleAppleApple
7ApplesAppleAppleApplesApple
8Apple LLCAppleAppleApple LLCApple
9BananaBananaBananaBananaBanana
10BananasBananaBananaBananasBanana
11Banana LLCBananaBananaBanana LLCBanana
12Cherry InvestmentCherry Investment
13BlackberryBlackberry
14Blue-berry LLCBlueberryBlueberry
Data
Cell Formulas
RangeFormula
C4C4=+COUNTA(C6:C14)-COUNTBLANK(C6:C14)
D6:D14D6=IF(C6="",B6,C6)
 
Upvote 0
OK, I think I see what you are doing.

This should be a lot faster:
VBA Code:
Sub Macro1()

    Dim lr As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Populate column C with formulas
    Range("C6:C" & lr).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Names,2,FALSE),"""")"
    
'   Change formulas to hard-coded values
    Range("C6:C" & lr).Value = Range("C6:C" & lr).Value

    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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