Excel-Not Responding State

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi everyone,
Here i am trying with this code for copying the values which are present in column 'B' based on column 'H' ,i have tried with the below code but it takes me lot of time , if i have huge data in my sheet, it goes to Excel-Not Responding State
Is their any other possible way to perform this

Here My main goal is to copy the values of column B that are present in between the values of column 'H' and paste that in another sheet
SlnoColumn B...Column H
11111212
2222
3333
4444
555512345
6666
777712333
8888
999912312
101000

<tbody>
</tbody>

Code:
Sub looping()
Dim lastrow, i As Long
lastrow = Cells(Rows.Count, "H").End(xlUp).Row
    For i = 2 To lastrow
        If Cells(i, 8).Value = "" Then
            Cells(i, 2).Copy
            Worksheets("Sheet2").Select
            Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
            Worksheets("Sheet2").Paste
            Worksheets("Sheet1").Select
        End If
    Next i
End Sub

Thanks in advance
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
All of the selecting and copying and pasting is not good practice. The code below loads everything into an array and uses that for the logic. A lot faster, and should take care of the 'not responding' garbage.

Code:
Sub looping2()
Application.ScreenUpdating = False
Dim ws1 As Worksheet: Set ws1 = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Dim AR() As Variant: AR = ws1.Range("A1:H" & Range("A" & Rows.Count).End(xlUp).Row).Value
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")


For i = LBound(AR) To UBound(AR)
    If AR(i, 8) = "" Then AL.Add AR(i, 2)
Next i


With ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(AL.Count)
    .Value = Application.Transpose(AL.toArray)
End With


Application.ScreenUpdating = True
End Sub
 
Upvote 0
All of the selecting and copying and pasting is not good practice. The code below loads everything into an array and uses that for the logic. A lot faster, and should take care of the 'not responding' garbage.

Code:
Sub looping2()
Application.ScreenUpdating = False
Dim ws1 As Worksheet: Set ws1 = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Dim AR() As Variant: AR = ws1.Range("A1:H" & Range("A" & Rows.Count).End(xlUp).Row).Value
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")


For i = LBound(AR) To UBound(AR)
    If AR(i, 8) = "" Then AL.Add AR(i, 2)
Next i


[COLOR=#ff0000]With ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(AL.Count)[/COLOR]
    .Value = Application.Transpose(AL.toArray)
End With


Application.ScreenUpdating = True
End Sub
Thanks for your effort, but i am getting an error in highlighted row as "Application defined or object defined error"
could you help me what changes i have to make

Thank you in advance
 
Upvote 0
Made a couple of small changes.

Code:
Sub looping2()
Application.ScreenUpdating = False
Dim ws1 As Worksheet: Set ws1 = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Dim AR() As Variant: AR = ws1.Range("A2:H" & ws1.Range("A" & Rows.Count).End(xlUp).Row).Value
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")


For i = LBound(AR) To UBound(AR)
    If AR(i, 8) = "" Then AL.Add AR(i, 2)
Next i


With ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(AL.Count)
    .Value = Application.Transpose(AL.toArray)
End With


Application.ScreenUpdating = True
End Sub
 
Upvote 0
That's working , Thank you and one more doubt, if i need to copy multiple cells and paste in different columns in Sheet2

Like Below Table , i need to copy Column'B' values from Sheet1 and paste in Column'A' in Sheet2 and copy Column'M' from Sheet1 and paste to Column'Z' in Sheet2

slnonamecolumn BColumn H Column M
1asedf111123450987
2qwer2229876543
3bsfdbfd3338765
4qwerf444543334567
5sadfdsf5558765423
6gedfgg66623459876345
7zvxcbvcjtr777763267
8eryewa8881345234586
9rtesd99923458754

<tbody>
</tbody>

Thanks in advance
 
Last edited:
Upvote 0
───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 
Upvote 0
That's working , Thank you and one more doubt, if i need to copy multiple cells and paste in different columns in Sheet2

Like Below Table , i need to copy Column'B' values from Sheet1 and paste in Column'A' in Sheet2 and copy Column'M' from Sheet1 and paste to Column'Z' in Sheet2

slnonamecolumn BColumn HColumn M
1asedf111123450987
2qwer2229876543
3bsfdbfd3338765
4qwerf444543334567
5sadfdsf5558765423
6gedfgg66623459876345
7zvxcbvcjtr777763267
8eryewa8881345234586
9rtesd99923458754

<tbody>
</tbody>

Thanks in advance

Can this be done????
 
Upvote 0
How about this?

Code:
Sub looping2()
Application.ScreenUpdating = False
Dim ws1 As Worksheet: Set ws1 = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Dim AR() As Variant: AR = ws1.Range("A2:M" & ws1.Range("A" & Rows.Count).End(xlUp).Row).Value
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")
Dim AL2 As Object: Set AL2 = CreateObject("System.Collections.ArrayList")




For i = LBound(AR) To UBound(AR)
    If AR(i, 8) = "" Then
        AL.Add AR(i, 2)
        AL2.Add AR(i, 13)
    End If
Next i




ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(AL.Count).Value = Application.Transpose(AL.toArray)
ws2.Range("Z" & Rows.Count).End(xlUp).Offset(1).Resize(AL2.Count).Value = Application.Transpose(AL2.toArray)


Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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