Need A Shorter Code

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
983
Hi Folks,

Anyone out there have time to write me a short code for the following please.

I want to search column B in worksheet1 starting from row 6 downwards and for every cell that is > "" i want to copy them and place them in column B of worksheet2 starting from row 6 and continue downwards.

I know how to do it like this for each cell:

If Sheets1.Range ("B6").value >"" then
sheets2.Range ("B6").value = Sheets1.Range ("B6").value
End If

But not sure how to do it short code


Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Assuming the blank cells are truly blank (that is, not just displaying as blank due to a formula result), how about this?

Code:
Sub test()
Dim myRng As Range

With Sheets("Sheet1")
    Set myRng = .Range("B6", .Range("B65536").End(xlUp))
End With

With myRng
    .SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
    .SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Sheet2").Range("B6")
    .Rows.Hidden = False
End With

End Sub
 

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
983
Hi Kristy,

Thank you very much that has done just what is needed.

Thank you again :biggrin: :biggrin: :biggrin:
 
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,168,117
Messages
5,857,482
Members
431,882
Latest member
saaaaaaaaaaaaaaaaaaaaaa

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