M
MikeZz
Hi,
I have a macro that creates a workbook with 2 sheets:
Sheet 1: Vehicle Information (500+ records)
10 Columns in a record that define a unique vehicle.
Sheet 2: Components in each Vehicle (28000+ records)
Same 10 Columns in a record that define a unique vehicle.
In db terms, the 10 columns are like the primary key from sheet 1.
15 additional columns which further define each comonent in each
vehicle.
Each record represents a unique Vehicle/Component combination.
I know this would be a great candidate for a real db but I don't have that
option.
I have my macro create the workbook and put auto filters on both sheets.
I'd like to somehow copy code from my master workbook to the new workbook
that will syncronize the auto filters on both sheets when ever the other one
is changed.
The column titles on Sheet 1 are duplicated on Sheet 2 but could be in a
different order (don't ask why... to hard to explain). Hopefully this won't
matter.
Anyway, I was thinking that I could probably do something in the Worksheet
Change Event... although I've never done anything other than straight Module
VBA programming.
So, what's the best way to do this and also, how do I get the code from my
Master file into the newly created file? I found the attached code off of
google but it doesn't explain exactly how I can embed it into a worksheet as
opposed to a module.
Thanks!
MikeZz
Sub CopyModule(SourceWB As Workbook, strModuleName As String, _
TargetWB As Workbook)
' copies a module from one workbook to another
' example:
' CopyModule Workbooks("Book1.xls"), "Module1", _
Workbooks("Book2.xls")
Dim strFolder As String, strTempFile As String
strFolder = SourceWB.Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & "\"
strTempFile = strFolder & "~tmpexport.bas"
On Error Resume Next
SourceWB.VBProject.VBComponents(strModuleName).Export strTempFile
TargetWB.VBProject.VBComponents.Import strTempFile
Kill strTempFile
On Error GoTo 0
End Sub
I have a macro that creates a workbook with 2 sheets:
Sheet 1: Vehicle Information (500+ records)
10 Columns in a record that define a unique vehicle.
Sheet 2: Components in each Vehicle (28000+ records)
Same 10 Columns in a record that define a unique vehicle.
In db terms, the 10 columns are like the primary key from sheet 1.
15 additional columns which further define each comonent in each
vehicle.
Each record represents a unique Vehicle/Component combination.
I know this would be a great candidate for a real db but I don't have that
option.
I have my macro create the workbook and put auto filters on both sheets.
I'd like to somehow copy code from my master workbook to the new workbook
that will syncronize the auto filters on both sheets when ever the other one
is changed.
The column titles on Sheet 1 are duplicated on Sheet 2 but could be in a
different order (don't ask why... to hard to explain). Hopefully this won't
matter.
Anyway, I was thinking that I could probably do something in the Worksheet
Change Event... although I've never done anything other than straight Module
VBA programming.
So, what's the best way to do this and also, how do I get the code from my
Master file into the newly created file? I found the attached code off of
google but it doesn't explain exactly how I can embed it into a worksheet as
opposed to a module.
Thanks!
MikeZz
Sub CopyModule(SourceWB As Workbook, strModuleName As String, _
TargetWB As Workbook)
' copies a module from one workbook to another
' example:
' CopyModule Workbooks("Book1.xls"), "Module1", _
Workbooks("Book2.xls")
Dim strFolder As String, strTempFile As String
strFolder = SourceWB.Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & "\"
strTempFile = strFolder & "~tmpexport.bas"
On Error Resume Next
SourceWB.VBProject.VBComponents(strModuleName).Export strTempFile
TargetWB.VBProject.VBComponents.Import strTempFile
Kill strTempFile
On Error GoTo 0
End Sub