error in loop

kutbishikari

New Member
Joined
Apr 12, 2011
Messages
3
here is my code

Sub hawally()
Application.ScreenUpdating = False
Set i = Sheets("Sheet3")
Set e = Sheets("HW")
Dim d As Integer
Dim j As Integer
d = 1
j = 2
e.Range("A2:D100").Clear

Do Until IsEmpty(i.Range("D" & j))
If i.Range("D" & j) > 0 Then
d = d + 1
e.Range("A" & d & ":D" & d & "").Value = i.Range("A" & j & ":D" & j & "").Value
End If
j = j + 1
Loop
Sheets("HW").Select
Application.ScreenUpdating = True

End Sub

my sheet has 700 rows with 10 columns , somewhere no numbers in the loop column , then it giving me mis type error and exit sub ,
i would like to go next by skip that error

my sheet look like

A B C D
df fr gt 8
df fr gt 6
df fr gt 4
df fr gt #value!
df fr gt 7
df fr gt 6

i would like to get result as below :
df fr gt 8
df fr gt 6
df fr gt 4
df fr gt 7
df fr gt 6
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try something like this...

Code:
Sub hawally2()

    Dim ws3 As Worksheet, wsHW As Worksheet
    Dim LastRow As Long
    
    Application.ScreenUpdating = False
    
    Set ws3 = Sheets("Sheet3")
    Set wsHW = Sheets("HW")

    wsHW.Range("A2", wsHW.Range("D" & Rows.Count).End(xlUp).Offset(1)).ClearContents
    
    With ws3
    
        LastRow = .Range("D" & Rows.Count).End(xlUp).Row
        
        .Range("D1:D" & LastRow).AutoFilter Field:=1, Criteria1:=">0"
        
        .Range("A2:D" & LastRow).SpecialCells(xlCellTypeVisible).Copy
        wsHW.Range("A2").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
        
        Application.CutCopyMode = False ' Clear clipboard
        .AutoFilterMode = False         ' Clear autofilter
        
    End With
    
    wsHW.Select
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Thanks AlphaFrog for your quick reply but it doesn't work , error 400 and nothing coping , marco taking long time ,previos code fast very fast

forget to mention sheet3 is a hidden sheet and it has 700 rows and 12 columns linked by some another sheets

your help will be appricaited
 
Upvote 0
Then to keep it simple...

Sub hawally()
Application.ScreenUpdating = False
Set i = Sheets("Sheet3")
Set e = Sheets("HW")
Dim d As Integer
Dim j As Integer
d = 1
j = 2
e.Range("A2:D100").Clear

Do Until IsEmpty(i.Range("D" & j))
If Not IsError(i.Range("D" & j)) Then
If i.Range("D" & j) > 0 Then
d = d + 1
e.Range("A" & d & ":D" & d & "").Value = i.Range("A" & j & ":D" & j & "").Value
End If
End If
j = j + 1
Loop
Sheets("HW").Select
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top