Paste on filtered data Visible Cells

Sufiyan97

Well-known Member
Joined
Apr 12, 2019
Messages
1,619
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Is it possible without macro?
I want to paste sheet2 values Range (B2:B5) into Filtered data Visible rows 3, 7, 12, 17 on sheet 1 below

Book1
A
1Name
3
7
12
17
28
Sheet1




Sheet 2

Book1
B
2B
3F
4K
5P
Sheet2
 
I try to Use column B at sheet1 to find Lastrow has Data .
Try this:
VBA Code:
Sub PasteatVisibleCells()
Dim i As Long, Lr As Long, Rng As Range, Sh1 As Worksheet, Sh2 As Worksheet, Cell As Range
Set Sh1 = Sheets("Sheet1")
Set Sh2 = Sheets("Sheet2")
Lr = Sh1.Range("B" & Rows.Count).End(xlUp).Row
Set Rng = Sh1.Range("A2:A" & Lr)
i = 2
For Each Cell In Rng
If Cell.EntireRow.Hidden = False Then
Cell.Value = Sh2.Range("B" & i).Value
i = i + 1
End If
Next Cell

End Sub
 
Upvote 0
It's pasting only 1 value

Book1
A
1Name
3B
7
12
17
Sheet1
 
Upvote 0
How about
VBA Code:
Sub alidurfani()
   Dim Cl As Range
   Dim i As Long
   
   i = 1
   For Each Cl In Sheets("Sheet1").Range("A:A").SpecialCells(xlVisible)
      i = i + 1
      Cl.Value = Sheets("Sheet2").Range("B" & i).Value
   Next Cl
End Sub
 
Upvote 0
How about
VBA Code:
Sub alidurfani()
   Dim Cl As Range
   Dim i As Long
  
   i = 1
   For Each Cl In Sheets("Sheet1").Range("A:A").SpecialCells(xlVisible)
      i = i + 1
      Cl.Value = Sheets("Sheet2").Range("B" & i).Value
   Next Cl
End Sub

Hello Fluff,

It's working but it is starting pasting from A1 as below and while running this code, Excels stops working

Book1
A
1B
3F
7K
12P
17
Sheet1
 
Upvote 0
However I have found another solution for it.

Book1
AB
1Row No.AAA
33B
77F
1212K
1717P
Sheet1
Cell Formulas
RangeFormula
A3,A17,A12,A7A3=ROW()
B3,B17,B12,B7B3=VLOOKUP(A3,Sheet2!$A$2:$B$5,2,0)



Sheet2

Book1
AB
1
23B
37F
412K
517P
Sheet2
 
Upvote 0

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