Paste the data in row 10

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,223,885
Messages
6,175,180
Members
452,615
Latest member
bogeys2birdies

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