Hi folks,
Relatively new to VBA and am trying to write a simple module. I have two worksheets, "tasks" and "worktask_calc".
On the worksheet "tasks" I have a list of user names in column A and a work type in B1 in the form of
WorkTypeA
userA
userB
userC
The worksheet "worktask_calc" is a large sheet containing information in the form of:
userA workTypeA 10.5
userA workTypeC 20
userA workTypeD 12
userB workTypeC 5
userC workTypeA 6
etc..
I wish to return the value in Cell C above to the "tasks" worksheet. ie. for the example above i will return:
WorkTypeA
userA 10.5
userB
userC 6
My code is below, and works fine if the work type and user are present in each iteration on the "workTask_calc" sheet. If they are not, the editor does not respond.
Any help would be much appreciated!Sub FindTasks() Dim i As Long Dim j As Long Dim name As String Dim workTypeA As String Dim workTypeB As String Dim workTypeC As String Dim timespent As String Application.ScreenUpdating = False ' Look for occurances of task B1 Sheets("Tasks").Select If Range("B1").Value <> "" Then i = 2 Do Until Range("A" + CStr(i)).Value = "" Sheets("Tasks").Select name = Range("A" + CStr(i)).Value workTypeA = Range("B1").Value j = 3 Sheets("WorkTask_Calc").Select Do Until Range("A" + CStr(j)).Value = "" Sheets("WorkTask_Calc").Select If Range("A" + CStr(j)).Value = name And Range("B" + CStr(j)).Value = workTypeA Then timespent = Range("C" + CStr(j)).Value Sheets("Tasks").Select Range("B" + CStr(i)).Value = timespent End If j = j + 1 Loop i = i + 1 Loop End If Application.ScreenUpdating = True End Sub
Thanks,
Ger