problems with this macro

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
I need a macro that will take the cell I'm on plus 78 cells to the right and four rows down, copy and paste the values in them, then replace the cells that have a zero with a blank. The macro below, will go down one cell and over one column and do that.

Also this macro has a bug in the line
cell.value = cell.value

Right now, it's taking everything that's in the first row, copying it, then pasting down 4 rows, so that the next 4 rows all look the same. What I need to do is simply copy and paste the values that are in the next 4 rows, not copy what is in the next row and paste it, so that the next 4 rows are all the same. Thanks

Code:
Sub removezeroes()
   
   Dim Cell As Range
   Dim RngFrom As Range
   Dim RngTo As Range
 
   Set RngFrom = Selection
   Set RngTo = Cells(RngFrom.Row + 1, 2).Resize(15, 78)
 
   Cells(RngFrom.Row, 2).Resize(, 78).Copy Destination:=RngTo
 
   For Each Cell In RngTo
      If Cell.Value = 0 Then
         Cell.Value = ""
      Else
         Cell.Value = Cell.Value
      End If
   Next Cell
 
   RngTo.Activate
 
   Set Cell = Nothing
   Set RngFrom = Nothing
   Set RngTo = Nothing
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

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