Thread: copy and paste
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default copy and paste

Form6 appears in two places in the code I posted. I assume you replaced both
with the same mix type numbe.

Let's do a quality check here. This is the illustration you posted:

a b c d
71 4056 1/3/08 5 7
72 4056 1/3/08 5 8
73 4058 1/5/08 3 4
74 4056 1/6/08 2 6
75 4058 1/7/08 3 5
76 4056 1/9/08 6 7
77 4056 1/9/08 7 9

It shows the mix type in column A and this is what the code is based on. Is
the illustration correct? If not then the code is searching the wrong column
for your mix type numbers. After looking at your ListBox click event code,
it appears that the data actually should look like this:

a b c d e
71 4056 1/3/08 5 7
72 4056 1/3/08 5 8
73 4058 1/5/08 3 4
74 4056 1/6/08 2 6
75 4058 1/7/08 3 5
76 4056 1/9/08 6 7
77 4056 1/9/08 7 9

with the mix type numbers in column B. In that case, change this line of
code:

If .Cells(i, 1) = Form6 Then

To:

If .Cells(i, 2) = Form6 Then


If that fixes the problem of not finding anything, then we can work on
getting the Form6 variable established.

"Eric" wrote:

I replaced form6 with 4059 and 4069 (they are the two mix types I have for
results at this time). Neather one worked. I got no errors. The macro went
through its passes but didn't copy the last four test results.

"JLGWhiz" wrote:

Try making Form6 = 4056 and see if it works.

"Eric" wrote:

when I use this macro it doesn't work. Nothing happens and I don't get any
error reports. I am at a loss. Here it is....

Sub last_four_four()


Dim lr4, lc4, mCnt, cnt As Long
With Worksheets("last four")
lr4 = .Cells(Rows.count, 2).End(xlUp).Row
lc4 = .UsedRange.Columns.count + 1
mCnt = Application.CountIf(.Range("A71:A" & lr4), form6)
If mCnt = 4 Then
mCnt = 4
End If
cnt = 1
For i = lr4 To 71 Step -1
If .Cells(i, 1) = form6 Then
If cnt <= 4 Then
Select Case mCnt
Case Is = 1
.Range(.Cells(i, 2), .Cells(i, lc4)).Copy .Range("B9")

Case Is = 2
If x = "" Then x = 10
.Range(.Cells(i, 2), .Cells(i, lc4)).Copy .Range("B&x")
x = x - 1

Case Is = 3
If x = "" Then x = 11
.Range(.Cells(i, 2), .Cells(i, lc4)).Copy .Range("B&x")
x = x - 1

Case Is = 4
If x = "" Then x = 12
.Range(.Cells(i, 2), .Cells(i, lc4)).Copy .Range("B&x")
x = x - 1

End Select
cnt = cnt + 1
End If
End If
Next
End With
End Sub

Where it says form6 I was told to use a variable. I was using a number of
101.

Any help would be appreciated. Thank you

Eric