copy & paste visible values with VBA

bademployee

Board Regular
Joined
Aug 19, 2010
Messages
184
Hi all,

I'm using this to hide any rows without a value in "deblending" B13:B40:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim r As Range, c As Range
Set r = Range("b13:b40")
Application.ScreenUpdating = False
For Each c In r
    If Len(c.Text) = 0 Then
        c.EntireRow.Hidden = True
    Else
        c.EntireRow.Hidden = False
    End If
Next c
Application.ScreenUpdating = True
End Sub

Leaves a list of values in A13:B40 (will only ever be a maximum number of 7 rows visible, usually only 2-3, but will have hidden rows between each visible row).

What I need is some VBA to copy & paste the visible values in A13:A40 to another sheet called "Blends" C9:C15.

Also, the visible values in B13:B40 copy & pasted to "Blends" R9:R15.

Thanks in advance.

Mark
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Sub CopyVisible()
'untested
Range("A13:A40").Specialcells(xlcelltypevisible).copy sheets("Blends").range("C9")
Range("B13:B40").specialcells(xlcelltypevisible).Copy Sheets("Blends").Range("R9")
End Sub
 
Last edited:
Upvote 0
Thanks BobUmlas.

I tried incorporating the 2 peices, but get a run-time error:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim r As Range, c As Range
Set r = Range("b13:b40")
Application.ScreenUpdating = False
For Each c In r
    If Len(c.Text) = 0 Then
        c.EntireRow.Hidden = True
    Else
        c.EntireRow.Hidden = False
    End If
Next c
Application.ScreenUpdating = True


[COLOR=#333333]Range("A13:A40").Specialcells(xlcelltypevisible).copy sheets("Blends").range("C9")[/COLOR]
[COLOR=#333333]Range("B13:B40").specialcells(xlcelltypevisible).Copy Sheets("Blends").Range("R9")

[/COLOR]End Sub

Any suggestions?

Mark
 
Upvote 0
Try BobUmlas's code by itself, see what happens?
It may be that you don't need to integrate it within your code?
Just throwing suggestions out there...

Regards
manc
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

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