Paste the data in row 10

sofas

Active Member
Joined
Sep 11, 2022
Messages
469
Office Version
  1. 2019
Platform
  1. Windows
Hello. I use this code to copy data from one sheet to another. My problem is that it pastes the data at the first empty cell in column C. What I want is to install the paste starting from cell C 10, regardless of whether there is data before the tenth row or not.


VBA Code:
Sub test()
Dim Sh1 As Worksheet, Sh2 As Worksheet
 Set Sh1 = Sheets("Sheet1"): Set Sh2 = Sheets("Sheet2")

Dim j&, i&, LASTROW&, X As String
Dim Rng As Range

X = Sh2.[B4]

LASTROW = Sh1.Cells(Rows.Count, 12).End(xlUp).Row
    
For j = 5 To LASTROW
If UCase(Sh1.Cells(j, 12)) = X Then
            
    Set Rng = Sh1.Range(Sh1.Cells(j, 3), Sh1.Cells(j, 30))
    
    
  '  You must paste in row 10 in column C
 
        Sh2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Resize(1, 28).Value = Rng.Value
        
        
        
        
      End If
    
    Next j
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi.
Try this:

VBA Code:
 '  You must paste in row 10 in column C
       If Sh2.[C10] = "" Then
        Sh2.[C10].Resize(1, 28).Value = Rng.Value
       Else: Sh2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Resize(1, 28).Value = Rng.Value
       End If
 
Upvote 0
Solution
Hi.
Try this:

VBA Code:
 '  You must paste in row 10 in column C
       If Sh2.[C10] = "" Then
        Sh2.[C10].Resize(1, 28).Value = Rng.Value
       Else: Sh2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Resize(1, 28).Value = Rng.Value
       End If
Thank you, this is what is needed
I had thought of a solution like this but now I use your code

VBA Code:
Dim dlr As Long
  dlr = sh2.Cells(Rows.Count, "c").End(xlUp).Row
     If dlr < 10 Then dlr = 10
      
    Set Rng = sh1.Range(sh1.Cells(j, 3), sh1.Cells(j, 30))
        sh2.Range("c" & dlr).Offset(1, 0).Resize(1, 28).Value = Rng.Value
      End If
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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