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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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.
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

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