Loop Copy portions of rows to another sheet

Mr_Ragweed2

Board Regular
Joined
Nov 11, 2022
Messages
145
Office Version
  1. 365
Platform
  1. Windows
Hello and much thanks in advance. I'm trying to write a loop that searches a range of rows (19-31) and if there is data in column C for that row then i want t paste columns C:U from that row into another sheet. It's been a long time since i've done this and VBA is not part of my regular work - so apologies for simple errors.

[Code starts here]
Dim i As Integer
For i = 19 To 31 These are the only rows that could contain data. it may be zero rows or all of them.
ThisFinal = Cells(Rows.Count, 1).End(xlUp).Row

If Sheets("Dekalb Seed Order Form").Cells(i, 3).Value <> "" Then

Sheets("Form Sheet").Rows(i).Select -This is where i'm wrong. This selects the whole row and i just want columns C:U from each row with data.
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

Selection.UnMerge (required due to huge formatting differences btwn the sheets)

Selection.Copy
Sheets("Order Summary").Select This is my attempt to paste it to the next available row on a different sheet
Cells(ThisFinal + 1, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Form Sheet").Activate

End If

Next i
[end code]

(sorry about code tags being wrong)
 
Yeah. I went back through and made sure to clear contents of all the cells. Then i stepped through the code and everything worked just fine ever since.
Many many thanks for your help on this.
Now i'm just working on code to copy 4 nonadjacent cells from the DekalbWS and copy them to the OSumWS on the next available row after the data you just helped me with.

But i'm assuming i need to start another thread for that if need help...

Thanks again!!
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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