Hello,
I'm new to VBA and coding is NOT my primary job function--I'm just trying to make a tedious task far less tedious for everyone involved. I have two workbooks with varied number of rows--one has consistent columns, the other's change both in column order and content. I need to pull the cell content from the varied-WB to the standardized WB based on the only guaranteed given value between the two WBs. The goal is to write a macro that I can use to update the Standard WB if the information is out of date. I can't share the files, so I'll do my best to illustrate the workbooks with easy data:
WB1 (standard, some columns may be filled in with old data or blank, "Type" column is constant)
WB2 (varied, order not constant)
I have created range names using the following code in an effort to simplify the main code (match/copy)
I don't know how to proceed further for the actual "heart" of the code, as I can't seem to get an "index/match" to work with the string variables (named ranges), and I can't hard set column locations as they are subject to change.
Any help is appreciated.
I'm new to VBA and coding is NOT my primary job function--I'm just trying to make a tedious task far less tedious for everyone involved. I have two workbooks with varied number of rows--one has consistent columns, the other's change both in column order and content. I need to pull the cell content from the varied-WB to the standardized WB based on the only guaranteed given value between the two WBs. The goal is to write a macro that I can use to update the Standard WB if the information is out of date. I can't share the files, so I'll do my best to illustrate the workbooks with easy data:
WB1 (standard, some columns may be filled in with old data or blank, "Type" column is constant)
Type | Family | Class |
cat | ||
dog | ||
snake |
WB2 (varied, order not constant)
Family | Type | Order | Class | Person |
felidae | cat | carnivora | mammalia | x |
canidae | dog | carnivora | mammalia | y |
Equidae | horse | Perissoda | mammalia | z |
Colubridae | snake | Squamata | Reptilia | a |
I have created range names using the following code in an effort to simplify the main code (match/copy)
VBA Code:
Sub column_names()
'' column_names Macro
'
Dim rng As Range
Dim wb As Workbook, ws As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
Set rng = ws.Range("data")
Application.DisplayAlerts = False
rng.CreateNames Top:=True
End Sub
I don't know how to proceed further for the actual "heart" of the code, as I can't seem to get an "index/match" to work with the string variables (named ranges), and I can't hard set column locations as they are subject to change.
Any help is appreciated.