KARTINA AZMAN
New Member
Hi.. i am cracking my head here trying to figure out how to do this. What I would like to do is to extract the value in column G of a workbook (different every month) and copy the value to a master workbook, into corresponding columns. Here is what I've got so far
After debugging so much, no more error showing but i do not get the result that i want.
Kindly help. I'm losing my mind.
Code:
Sub extract()
Dim master As Worksheet
Dim procCode, MIScode As String
Dim mnth As Integer
Dim i, j, lastrow As Long
Set master = ThisWorkbook.Worksheets(3)
With ActiveSheet
lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
'MsgBox lastrow
mnth = InputBox("Enter number of corresponding month", "MONTH INDEX")
For j = 8 To 77
procCode = master.Cells(j, 2).Value 'j is row counter for master
For i = 5 To lastrow
MIScode = ActiveSheet.Cells(i, 2).Value 'i is row counter for master
If ActiveSheet.Cells(i, 1).Value = "OUTPATIENT" Then
If procCode = MIScode Then
ActiveSheet.Cells(i, 7).Copy master.Cells((mnth + 6), j) 'value to copy is in activesheet,col G to copy to master.worksheets(3)
End If
ElseIf ActiveSheet.Cells(i, 1).Value = "EMYpatient" Then
If procCode = MIScode Then
ActiveSheet.Cells(i, 7).Copy master.Cells((mnth + 19), j) 'value to copy is in activesheet,col G to copy to master.worksheets(3)
End If
ElseIf ActiveSheet.Cells(i, 7).Value = "Inpatient" Then
If procCode = MIScode Then
ActiveSheet.Cells(i, 7).Copy master.Cells((mnth + 32), j) 'value to copy is in activesheet,col G to copy to master.worksheets(3)
End If
End If
Next i
Next j
End Sub
After debugging so much, no more error showing but i do not get the result that i want.
Kindly help. I'm losing my mind.