Drumin_Phreak
New Member
- Joined
- Oct 10, 2016
- Messages
- 25
I am sorry if this has been explained, but I have searched extensively for this to be answered. However, let me first explain what I am trying to do:
I am attempting to take a value from the working workbook (workbook "A") check and see if the value exists in the validating workbook (workbook "B") and then copying the corresponding values (all on the same row) from workbook "B" to workbook "A". If the value is not found a message box is displayed "value cannot be found".
Having said all that, I am really asking for someone to explain to me what part of the code is what. I am not here to have someone to do my work for me, rather just help me come to understand what does what. I am here to learn; usually I am very good at deciphering and modifying code. This has me stumped! so without further ado
I have this code that i found and i think with some modifications it can work:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Dim MyPath, MyFile, MySheet, MyCell1, MyCell2, MyCell3, MyCell4 ' worksheet
Dim R, C ' row, column
Sub TestGetValue1()
MyPath = "Path to validating workbook" ' path
MyFile = "Validation.xls" ' file
MySheet = "02" ' sheet
MyCell1 = "B2920" ' range
MyCell2 = "I2920" ' range
MyCell3 = "J2920" ' range
MyCell4 = "K2920" ' range
'------------------------------------------------------------------------
Cells(ActiveCell.Row, 5).Value = GetValue(MyPath, MyFile, MySheet, MyCell2)
Cells(ActiveCell.Row, 16).Value = GetValue(MyPath, MyFile, MySheet, MyCell3)
Cells(ActiveCell.Row, 17).Value = GetValue(MyPath, MyFile, MySheet, MyCell4)
'------------------------------------------------------------------------
End Sub
Private Function GetValue(Fpath, Ffile, Fsheet, Fref)
Dim XL4macro As String
'- Excel 4 macro string (requires R1C1 reference)
XL4macro = "'" & Fpath & "[" & Ffile & "]" & Fsheet & "'!" & _
Range(Fref).Address(ReferenceStyle:=xlR1C1)
'-------------------------------------------------------------------------
'-Run the macro
GetValue = ExecuteExcel4Macro(XL4macro)
End Function</code>
I am attempting to take a value from the working workbook (workbook "A") check and see if the value exists in the validating workbook (workbook "B") and then copying the corresponding values (all on the same row) from workbook "B" to workbook "A". If the value is not found a message box is displayed "value cannot be found".
Having said all that, I am really asking for someone to explain to me what part of the code is what. I am not here to have someone to do my work for me, rather just help me come to understand what does what. I am here to learn; usually I am very good at deciphering and modifying code. This has me stumped! so without further ado
I have this code that i found and i think with some modifications it can work:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Dim MyPath, MyFile, MySheet, MyCell1, MyCell2, MyCell3, MyCell4 ' worksheet
Dim R, C ' row, column
Sub TestGetValue1()
MyPath = "Path to validating workbook" ' path
MyFile = "Validation.xls" ' file
MySheet = "02" ' sheet
MyCell1 = "B2920" ' range
MyCell2 = "I2920" ' range
MyCell3 = "J2920" ' range
MyCell4 = "K2920" ' range
'------------------------------------------------------------------------
Cells(ActiveCell.Row, 5).Value = GetValue(MyPath, MyFile, MySheet, MyCell2)
Cells(ActiveCell.Row, 16).Value = GetValue(MyPath, MyFile, MySheet, MyCell3)
Cells(ActiveCell.Row, 17).Value = GetValue(MyPath, MyFile, MySheet, MyCell4)
'------------------------------------------------------------------------
End Sub
Private Function GetValue(Fpath, Ffile, Fsheet, Fref)
Dim XL4macro As String
'- Excel 4 macro string (requires R1C1 reference)
XL4macro = "'" & Fpath & "[" & Ffile & "]" & Fsheet & "'!" & _
Range(Fref).Address(ReferenceStyle:=xlR1C1)
'-------------------------------------------------------------------------
'-Run the macro
GetValue = ExecuteExcel4Macro(XL4macro)
End Function</code>