I am struggling with an excel vba macro which will update the contents of a spreadsheet (call it the client activity log) with values from the master log spreadsheet when client log file is opened. The method which I was using was to copy and paste cells since I keep getting errors when I try to assign values directly. I know that this is poor form, and I have stability issues with the client log macro crashing sometimes for unclear reasons. So I'm trying to clean this up (and avoid copying unwanted formatting).
What I am doing now is:
Private Sub Workbook_Open()
...
Run "Sheet2.UpdateActivites"
End Sub
The code for Sheet2:
Sub UpdateActivites()
...
Set MasterClientListWb = _
Workbooks.Open(pathToMasterLogs & "Master Client Database.xlsx")
Set MasterClientListWs = MasterClientListWb.Sheets("Sheet1")
MasterClientListWs.Range("A2").Select
For i = 1 To MasterClientListWs.UsedRange.Rows.Count
If ActiveCell.Value = clientNumber Then
' Sets last name
ActiveCell.Offset(columnoffset:=1).Copy
Me.Range("C1").PasteSpecial
' A lot more similar statements
End If
Next i
As I understand it, what I should be doing is more like:
Me.Cells("C1").Value = ActiveCell.Offset(columnoffset:=1).Value
but this throws an error whenever it runs. I suspect I may be referring to the file which I am opening vs the file which is running the macro incorrectly somehow.
I would really appreciate any help, I have fairly little experience with vba, as this no doubt shows. Thanks