Based on the earlier thread that i posted, How do i extract merged data and put them into different worksheets? Everything seems fine until my program encounter the
"program not responding error"
which I think is due to using
Sheets(sheetname).UsedRange.Rows.count
(because of deleting and clearing rows) which cause this to happen. Based on other thread discussions, I tried to use this instead
Cells(Sheets("SheetName").Rows.Count, 1).End(xlup).Row
(better options as suggested by others) but it didnt give me the result that I want which is as shown below. So how do I modify my below code to solve the program not responding error in this case and still get the ideal scenario as shown below?
Put the extracted data into 3 different sheets namely index 1, index 2 and index 3 as shown below
Sub UpdateVal()
Static count As Long
Dim iRow As Long
Dim aRow As Long
Dim a As Long
Dim b As Long
Dim selectRange As Range
dim lastline as integer
dim sheetname as string
dim indexrowcount as integer
dim wb as workbook
dim ws as worksheet
set wb= activeworkbook
set ws=wb.sheets(Index)
j = 2
iRow = 1
LastLine = ActiveSheet.UsedRange.Rows.count
While iRow < LastLine + 1
a = iRow + 1
b = iRow + 17 ' Max Group Size with Same name in F to H column
count = 1
If ws.Cells(iRow, "F").Value = "Martin1" Then
sheetname = "Index1"
ElseIf ws.Cells(iRow, "F").Value = "John1" Then
sheetname = "Index2"
Else
sheetname = "Index3"
End If
For aRow = a To b
If ws.Cells(iRow, "F") = ws.Cells(aRow, "F") And ws.Cells(iRow, "G") = ws.Cells(aRow, "G") And ws.Cells(iRow, "H") = ws.Cells(aRow, "H") Then
count = count + 1
Else
Set selectRange = Range("A" & iRow & ":J" & aRow - 1)
selectRange.Copy
indexrowcount = Sheets(sheetname).UsedRange.Rows.count
Sheets(sheetname).Range("A" & indexrowcount).PasteSpecial xlPasteAll
iRow = iRow + count
Exit For
End If
Next aRow
Wend