Solved: updating data regularly between 2 workbooks
Hi All ,
I have 2 spreadsheets. I need to pull gross salary info from one to another by clicking a refresh button. I thought I could use employee reference no as an unique number to match the records and pull gross salary regularly. Do we have a code for this I could use by changing necessary bits?
Cheers
Yeliz
1 Attachment(s)
Updating specific column using Vlookup in VBA
I've found below code to use Vlookup function in VBA to pull gross salary from one workbook to another by using employeeID. However I'm not sure which bits I need to change to apply it on my workbooks(attached). Can anyone tell me which parts I need to change in below code?
[VBA]Sub TestLookup()
Dim FileName As String
FileName = "C:\yeliz\gross salary.xls"
adoLookup FileName, ActiveSheet.Cells(2, 1)
End Sub
Sub adoLookup(FileName As String, luValue As String)
Dim adoRs As New ADODB.Recordset
Dim adoConn As New ADODB.Connection
Dim query As String
Dim col As Integer
With adoConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & FileName & ";Extended Properties=Excel 8.0;"
.Open
End With
query = "SELECT * FROM [Sheet1$A1:D6000]"
With adoRs
.CursorLocation = adUseClient
.Open query, adoConn, adOpenStatic, adLockReadOnly, adCmdText
.Fields(0).Properties("Optimize") = True
.Find "EmployeeID = '" & luValue & "'"
If Not .EOF Then
For col = 1 To 3
ActiveSheet.Cells(5, col + 1) = .Fields(col)
Next
Else
MsgBox "Employee " & luValue & " could not be found.", vbOKOnly, "Invalid ID"
End If
End With
End Sub[/VBA]