Delete Blank Cells

billfold

New Member
Joined
Apr 30, 2012
Messages
6
So, I need some help deleting blank cells, or adjusting my code to only copy cells in the range that have a value. Here are the steps:


  1. Copy Range B2:B2000 (which has formulas in it)
  2. Paste the Values of that Range into J2:J2000
  3. Then copy that range however many times the user wants it copied into one column. I was able to get this to work, but there are blanks copied over.

Also, this site always used to come up when I would search for some excel answers, but for some reason never pops up anymore.

Here is the code:

Code:
Sub copy()
Dim mR As Range


Worksheets("UserStoreList").Range("B2:B2000").Copy
Worksheets("UserStoreList").Range("J2:J2000").PasteSpecial xlPasteValues


Set mR = Worksheets("UserStoreList").Range("J2:J2000")
Dim HowManyTimes As Integer: HowManyTimes = Worksheets("US Form").Range("D52")


mR.Copy Worksheets("Sheet2").Range("A2").Offset(0).Resize(mR.Rows.Count * HowManyTimes)


Worksheets("UserStoreList").Range("J2:J2000").Delete


End Sub

Thank you for your help everyone.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,092
Office Version
  1. 365
Platform
  1. Windows
Try
Code:
Sub billfold()
Dim mR As Range


With Worksheets("UserStoreList")
   .Range("J2:J2000").Value = .Range("B2:B2000").Value
   .Range("J2:J2000").SpecialCells(xlBlanks).Delete xlUp
   Set mR = .Range("J2", .Range("J" & Rows.Count).End(xlUp))
End With
Dim HowManyTimes As Integer: HowManyTimes = Worksheets("US Form").Range("D52")


mR.copy Worksheets("Sheet2").Range("A2").Offset(0).Resize(mR.Rows.Count * HowManyTimes)


Worksheets("UserStoreList").Range("J2:J2000").Delete


End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,092
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,715
Messages
5,833,284
Members
430,201
Latest member
Deepakpilla36

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