Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50273

VBA code causing excel to hangup/ not respond

$
0
0
Hi,
Following code is part of larger macro that will copy any file in a given folder into one spreadsheet. This part of the code works to the extent that it does the match and copies to 'combined sheet' but then it just hangs like it is still looping. Eventually excel does not respond. Appreciate any feedback on what I am doing wrong.


Code:

    Dim t As Range, ss As Worksheet, zs As Worksheet, cs As Worksheet, tmatch As Range

        Set ss = Worksheets("affs")
        Set cs = Worksheets("Combinedsheet")

        For Each t In ss.Columns(9).Cells
            If t.Value = "Ticket Number" Then
                If t.Value = "" Then Exit For
            End If
   
            For Each zs In Wb1.Sheets ' was: ThisWorkbook.Sheets
                If Left(zs.Name, 9) = "aviswkly_" Then
                    Set tmatch = zs.Columns(9).Find(What:=t.Value)
                   
                    If Not tmatch Is Nothing Then
                        cs_last_row = cs.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
                        cs.Range("A" & cs_last_row & ":Q" & cs_last_row).Value = zs.Range("A" & tmatch.Row & ":Q" & tmatch.Row).Value
                        cs.Range("R" & cs_last_row & ":AQ" & cs_last_row).Value = ss.Range("A" & t.Row & ":Z" & t.Row).Value
                    End If
                End If
            Next zs
        Next t


Viewing all articles
Browse latest Browse all 50273

Latest Images

Trending Articles



Latest Images