Hi everyone,
I have a "main" worksheet that has a set of values. Based on this set of values I have another worksheet that has the list of the possible values(basically a look-up table) and corresponding codes that need to be retrieved and placed into another cell in the "main" worksheet. I have the code to do this(see below). My problem is the speed at which the whole process takes. For each record I have to switch back and forth between the worksheets. Is there a better method to accomplish this task at a faster speed?
CODE:
Sub Test()
Dim c As Range
Dim sFirstHit As String
Dim i
Dim j
Dim k
ThisWorkbook.Worksheets("MEDEP LabData EDD template"
.Activate
ro = ActiveSheet.UsedRange.Rows.Count 'Total number of rows that contain data
ro1 = ThisWorkbook.Worksheets("Look up table"
.UsedRange.Rows.Count 'Total number of rows that contain data
co = ActiveSheet.UsedRange.Columns.Count 'Total number of columns that contain data
For r = 4 To ro 'Start at row 4 and go to the end of data
i = Cells(r, 29)
Cells(r, 29).NumberFormat = "general"
ThisWorkbook.Worksheets("Look up table"
.Activate 'goto look-up worksheet
With Columns(1)
Set c = .Find(i, LookIn:=xlValues) 'find value that matches data in main worksheet
sFirstHit = c.Address
k = c.Offset(0, 1) 'Get value in next cell that corresponds to original value
End With
ThisWorkbook.Worksheets("Main"
.Activate
Cells(r, 13) = k 'Set cell to new data
Next
End Sub
Thanks
Jim
I have a "main" worksheet that has a set of values. Based on this set of values I have another worksheet that has the list of the possible values(basically a look-up table) and corresponding codes that need to be retrieved and placed into another cell in the "main" worksheet. I have the code to do this(see below). My problem is the speed at which the whole process takes. For each record I have to switch back and forth between the worksheets. Is there a better method to accomplish this task at a faster speed?
CODE:
Sub Test()
Dim c As Range
Dim sFirstHit As String
Dim i
Dim j
Dim k
ThisWorkbook.Worksheets("MEDEP LabData EDD template"
ro = ActiveSheet.UsedRange.Rows.Count 'Total number of rows that contain data
ro1 = ThisWorkbook.Worksheets("Look up table"
co = ActiveSheet.UsedRange.Columns.Count 'Total number of columns that contain data
For r = 4 To ro 'Start at row 4 and go to the end of data
i = Cells(r, 29)
Cells(r, 29).NumberFormat = "general"
ThisWorkbook.Worksheets("Look up table"
With Columns(1)
Set c = .Find(i, LookIn:=xlValues) 'find value that matches data in main worksheet
sFirstHit = c.Address
k = c.Offset(0, 1) 'Get value in next cell that corresponds to original value
End With
ThisWorkbook.Worksheets("Main"
Cells(r, 13) = k 'Set cell to new data
Next
End Sub
Thanks
Jim