how do we fill in school.xlsx file age column from age.xlsx file by using name column with visual b

%3CLINGO-SUB%20id%3D%22lingo-sub-2291168%22%20slang%3D%22en-US%22%3Ehow%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visual%20b%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291168%22%20slang%3D%22en-US%22%3E%3CP%3Ehow%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visual%20basic%20excel%3F%20Tables%20have%20variable%20length%20and%20have%20more%20than%2010000%20rows.%3C%2FP%3E%3CP%3Eschool.xlsx%3CBR%20%2F%3E%3CBR%20%2F%3E%7CA%20%7C%20B%20%7C%20C%7C%3CBR%20%2F%3E%7C%3A----%20%7C%3A------%3A%7C%20-----%3A%7C%3CBR%20%2F%3E%7Cname%20%7C%20code%20%7C%20age%7C%3CBR%20%2F%3E%7Cpeter1%20%7C%20254%20%7C%3CBR%20%2F%3E%7Cjane2%20%7C153%20%7C%3CBR%20%2F%3E%7Cted%20%7C%20323%20%7C%3CBR%20%2F%3E%7Cpeter3%20%7C323%20%7C%3C%2FP%3E%3CP%3Eage.xlsx%3CBR%20%2F%3E%7CA%20%7CB%7C%3CBR%20%2F%3E%7C%3A----%20%7C%3A------%3A%7C%3CBR%20%2F%3E%7Cname%20%7Cage%7C%3CBR%20%2F%3E%7Cmark3%7C%201%2C2%7C%3CBR%20%2F%3E%7Cpeter1%20%7C%205%20%7C%3CBR%20%2F%3E%7Cjane2%20%7C%201%2C5%7C%3C%2FP%3E%3CP%3E'''%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20Insertdata()%3CBR%20%2F%3EDim%20iAge%20As%20Integer%3CBR%20%2F%3ESet%20src%3DWorkbooks.Open(%22age.xlsx%22%2C%20True%2C%20True)%3CBR%20%2F%3EiAge%20%3D%20src.Worksheets(%22Sheet1%22).Range(%22B2%22).Value%3CBR%20%2F%3EWorksheets(%22Sheet1%22).Range(%22C2%22).Value%20%3D%20iAge%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E'''%3CBR%20%2F%3ENow%20the%20program%20returns%20value%201%20in%20field%20C2%20in%20age.xlsx%20file.%3CBR%20%2F%3EHow%20do%20we%20remake%20the%20program%20to%20insert%20age%20data%20in%20right%20row%20in%20shcool.xlsx%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2291168%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291211%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291211%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1036749%22%20target%3D%22_blank%22%3E%40sergey989%3C%2FA%3E%26nbsp%3BWhy%20VBA%3F%20A%20simple%20VLOOKUP%20or%20INDEX%2FMATCH%20(or%20XLOOKUP%20if%20your%20Excel%20version%20supports%20it)%20can%20do%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291233%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291233%22%20slang%3D%22en-US%22%3Ecan%20you%20show%20me%20example%3F%3CBR%20%2F%3Ebut%20we%20have%20variable%20length%20column%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291364%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291364%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1036749%22%20target%3D%22_blank%22%3E%40sergey989%3C%2FA%3E%26nbsp%3BSee%20attached%20example.%20I%20chose%20to%20put%20the%20data%20in%20structured%20tables.%20All%20three%20lookup%20methods%20are%20in%20the%20table%20at%20the%20top%20under%20age1%2C%20age2%20and%20age3.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20if%20you%20can%20get%20it%20to%20work%20on%20your%20side.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291388%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291388%22%20slang%3D%22en-US%22%3E%3CP%3Ecan%20we%20make%20in%20two%20different%20files%20and%20very%20large%20and%20very%20large%20variable%20length%20table%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291412%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291412%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1036749%22%20target%3D%22_blank%22%3E%40sergey989%3C%2FA%3E%26nbsp%3BYes%20you%20can.%20Look%20at%20the%20MS%20support%20pages%20for%20the%20function%20you%20want%20to%20use%20and%20follow%20the%20instructions%20there.%20Not%20much%20more%20I%20could%20do%20than%20repeat%20what%20has%20been%20written%20there%20already.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2291517%22%20slang%3D%22en-US%22%3ERe%3A%20how%20do%20we%20fill%20in%20school.xlsx%20file%20age%20column%20from%20age.xlsx%20file%20by%20using%20name%20column%20with%20visua%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291517%22%20slang%3D%22en-US%22%3E%3CP%3Ebut%20excel%20stall%20when%20i%20copy%20large%20columns%20.%3C%2FP%3E%3CP%3E%3D%D0%95%D0%A1%D0%9B%D0%98%D0%9E%D0%A8%D0%98%D0%91%D0%9A%D0%90(%D0%92%D0%9F%D0%A0(%5B%40%5Bname%20%5D%5D%3BtblAge%3B2%3B0)%3B%22Not%20found%22)%3CBR%20%2F%3ECan%20we%20put%20this%20code%20in%20vba%20macros%20and%20how%20to%20make%20faster%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

how do we fill in school.xlsx file age column from age.xlsx file by using name column with visual basic excel? Tables have variable length and have more than 10000 rows.

school.xlsx

|A | B | C|
|:---- |:------:| -----:|
|name | code | age|
|peter1 | 254 |
|jane2 |153 |
|ted | 323 |
|peter3 |323 |

age.xlsx
|A |B|
|:---- |:------:|
|name |age|
|mark3| 1,2|
|peter1 | 5 |
|jane2 | 1,5|

'''

 

Sub Insertdata()
Dim iAge As Integer
Set src=Workbooks.Open("age.xlsx", True, True)
iAge = src.Worksheets("Sheet1").Range("B2").Value
Worksheets("Sheet1").Range("C2").Value = iAge
End Sub


'''
Now the program returns value 1 in field C2 in age.xlsx file.
How do we remake the program to insert age data in right row in shcool.xlsx?

18 Replies

@sergey989 Why VBA? A simple VLOOKUP or INDEX/MATCH (or XLOOKUP if your Excel version supports it) can do this.

can you show me example?
but we have variable length column

@sergey989 See attached example. I chose to put the data in structured tables. All three lookup methods are in the table at the top under age1, age2 and age3.

 

See if you can get it to work on your side.

can we make in two different files and very large and very large variable length table?

@sergey989 Yes you can. Look at the MS support pages for the function you want to use and follow the instructions there. Not much more I could do than repeat what has been written there already.

but excel stall when i copy large columns .

=ЕСЛИОШИБКА(ВПР([@[name ]];tblAge;2;0);"Not found")
Can we put this code in vba macros and how to make faster?

@sergey989 Please provide a bit more info, otherwise we will go back and forth without achieving anything. Perhaps you can upload some files that are like your real ones and then I can perhaps enter the required formulae. From Google translate I understand that you are going for "ВПР" = VLOOKUP

sample two files

how do we fill in school.xlsx file age column from age.xlsx file by using key name column with visual basic excel? Tables have variable length and have more than 10000 rows.

school.xlsx

@sergey989 Two files attached. This time I just used the data as you provided it. Didn't bother to create structured tables. You need to have both files open.

 

how do i make condition in cell for example that i have value of cell in shool.xlsm file and i don't want it will be lost but formula work only for those values that exist in age.xlsx? Another words new values.

how do we instead of Not found value in third column in shcool.xlsm file have previous value that was stored before from early version of file age.xlsx? example attach

for example, BRS43 now have value Not found but ealier it has value 2. How can we make that file school.xlsm store previous values and formula do not erase previous value and only update some rows with values from newer age.xlsx file.

@sergey989 Sorry, I don't understand. Perhaps @Sergei Baklan can help out. You can communicate with him in Russian.

@Riny_van_Eekelen 

Sorry, VBA is not my territory. If I understood correctly if the value is not found in age we keep it in school as it is, otherwise take value from age.

I'd use Power Query to combine data such way if that's suitable.

@Sergei Baklan 

 

how do we instead of Not found value in third column in shcool.xlsm file have previuos value that was stored before from early version of file age.xlsx? example attach

for example BRS43 now have value Not found but ealier it has value 2. How can we make that file school.xlsm store previos values and formula do not earese previuos value and only update some rows with values from newer age.xlsx file.

how do we instead of Not found value in third column in shcool.xlsm file have previous value that was stored before from early version of file age.xlsx? example attach
for example, BRS43 now have value Not found but ealier it has value 2. How can we make that file school.xlsm store previous values and formula do not erase previous value and only update some rows with values from newer age.xlsx file. New verion of file included.

how about idea to use another shool2.xlsx file that renew only old values with old values where value return by formula is Not found

@sergey989 

If to keep previous value in stack and return into the same cell result of calculation or previous value, depends on condition, that's only with VBA. Can't help with it.

If Power Query it'll be one more table which merge these two ranges and return the value from one or another depends on they match or not. Mockup is in attached file.

How dose file school.xlsm was made with power query?

how does Mockup make?