vba - Excel Macro using the replace function between sheets -
I have a list of numbers on sheet 1 (TBPRT), the numbers are in the range of A2: A3900.
I have a list of those numbers on sheet 2 (sheet 1) with the respective manufacturers, Category A2: 1390 (Construction of names) and B2: 1390 (Manufacturer numbers). I need to change the number of tblparts with the names of manufacturers from sheet 1. I
I am getting a "run-time error 424":. Required on object line 10
sub macro1 () I dim the integer as the dim findstr string as the dim repstr as string 1390 i = 2 for findstr = sheet1.Range (" B. "in & amp; i) .Value RepStr = Sheet1.Range ('A' in & amp; i) .Value tblParts.Range (" One: One ") cells. Change what: = findstr, Replacement: = RepStr Next I end the sub
What is defined in the macro is what is
tblParts and you have to set it by using
set , because it is a complex object and is not a primitive.
For example, assuming the following should work
tblParts is defined and set to
"Sheet1" in the active workbook: < Pre class = "lang-vb prettyprint-override">
options clear 'always a good idea! Sub-macro1 () dim tblParts worksheet dim I set the string set in the form of dim findstr string retard repStr as tblParts = ActiveWorkbook.Sheets ("tblparts") as sht = ActiveWorkbook.Sheets ("Sheet1") I = 2 for 1390 findstr = Sht.Range ("B" in & amp; i) .Value RepStr = Sht.Range ('A' in & amp; i) .Value tblParts.Range ("One: One") . Cells.Replace what: = findstr, replacement: = RepStr next I End sub
option clear on top to clearly declare all your variables Will force. If you do not do this, consider that type as
variant
Comments
Post a Comment