My Code has a Tick it wont paste to the right row.

Warpug

New Member
Joined
Apr 13, 2017
Messages
19
Office Version
  1. 365
Platform
  1. Windows
For some reason my data keeps being pasted to row three on my target sheet. I wanted it to begin in row 2 on the target sheet, but this code is doing something i dont understand. The first hit I get that fits my criteria, is in row 3 on my Data sheet, and its being placed in row three on my target sheet leaving row two blank and then each hit after the first is going on the next row. In this small test data set I have hits on rows 3,5 and 7 but they are being populated on the Target sheet on rows 3,4 and 5. Please help.

Sub SIDMOVER2()
Dim dsht As Worksheet
Dim tsht As Worksheet
Set dsht = ThisWorkbook.Sheets("Data")
Set tsht = ThisWorkbook.Sheets("Target")
lRow = dsht.Cells(Rows.Count, 1).End(xlUp).Row
y = 2
For x = 2 To lRow
If dsht.Cells(x, 2) Like "[a-zA-Z]######" Then
tsht.Cells(y, 1) = dsht.Cells(x, 1)
tsht.Cells(y, 2) = dsht.Cells(x, 2)
tsht.Cells(y, 3) = dsht.Cells(x, 3)
ElseIf dsht.Cells(x, 2) Like "FUND" Then
tsht.Cells(y, 1) = dsht.Cells(x, 1)
tsht.Cells(y, 2) = dsht.Cells(x, 2)
tsht.Cells(y, 3) = dsht.Cells(x, 3)
Else
y = y + 1
End If
Next x
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Untested, but maybe this:

Code:
y = 2
For x = 2 To LRow
If dsht.Cells(x, 2) Like "[a-zA-Z]######" Then
    tsht.Cells(y, 1) = dsht.Cells(x, 1)
    tsht.Cells(y, 2) = dsht.Cells(x, 2)
    tsht.Cells(y, 3) = dsht.Cells(x, 3)
    y = y + 1
ElseIf dsht.Cells(x, 2) Like "FUND" Then
    tsht.Cells(y, 1) = dsht.Cells(x, 1)
    tsht.Cells(y, 2) = dsht.Cells(x, 2)
    tsht.Cells(y, 3) = dsht.Cells(x, 3)
    y = y + 1
End If
Next x
 
Upvote 0
Untested, but maybe this:

Code:
y = 2
For x = 2 To LRow
If dsht.Cells(x, 2) Like "[a-zA-Z]######" Then
    tsht.Cells(y, 1) = dsht.Cells(x, 1)
    tsht.Cells(y, 2) = dsht.Cells(x, 2)
    tsht.Cells(y, 3) = dsht.Cells(x, 3)
    y = y + 1
ElseIf dsht.Cells(x, 2) Like "FUND" Then
    tsht.Cells(y, 1) = dsht.Cells(x, 1)
    tsht.Cells(y, 2) = dsht.Cells(x, 2)
    tsht.Cells(y, 3) = dsht.Cells(x, 3)
    y = y + 1
End If
Next x
That worked! Thanks again
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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