Require Changing in VBA Code

Navi_G

Board Regular
Joined
May 30, 2018
Messages
94
Office Version
  1. 2016
Platform
  1. Windows
Hi Experts,
I design a VBA code to search multiple items in my range (A2:D100) when I write cut # in (I2) the data against that cut could copy and paste in Range (A5:L100) in empty cell and at the last the curser should come in range (i2). my code is running without any error its curser come in Range (I2) but is not coping and pasting data pls some one check my code and correct it.
Report.xlsm
VBA Code:
Sub Button3_Click()
Application.ScreenUpdating = False
Dim x As String
Dim y As Integer
Dim Z As Integer
Range("i5:i100").ClearContents
x = Sheet1.Range("i2").Value
y = Sheet1.Range("a100").End(xlUp).Row
For Z = 2 To y
If Cells(Z, 1) = x Then
Range(Cells(Z, 1), Cells(Z, 5)).Copy
Range("i100").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
End If
Next Z
Application.CutCopyMode = False
Range("i2").Select

End Sub

Thanks in advance.
Regards,
Navi_G
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,096
Office Version
  1. 2016
Platform
  1. Windows
When a1:a100 is filled then Sheet1.Range("a100").End(xlUp).Row = 1
Then your loop For Z = 2 to Y is finally 2 to 1 and that is no loop.
 

Forum statistics

Threads
1,141,406
Messages
5,706,269
Members
421,437
Latest member
GijoeBlack

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
Top