macro required

L

Legacy 178446

Guest
Hi there,

I have values in two columns A and C. I need to write a macro to copy the values in every 11th cell in both columns to a new worksheet. The first value in column A that I would like to copy is in row 32. So the subsequent values are in rows 43,54,65 etc. In column c, the first value is in row 36. So the subsequent values are in rows 47,58,69 etc. The number of rows is varies. The code I'm using is:

Code:
Sub Copy10()
Dim LR As Long, i As Long, ws As Worksheet
Set ws = ActiveSheet
Worksheets.Add
With ws
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 32 To LR Step 11
        .Range("A" & i).Copy Destination:=Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 36 To LR Step 11
        .Range("A" & i).Copy Destination:=Range("B" & Rows.Count).End(xlUp).Offset(1)
    Next i
End With
End Sub

Im getting error message when I do this even though this code has worked before! It just says 'microsoft visual basci' and '400' Does anyone know where i'm going wrong?:confused:

Thanks in advance for the help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Should it not be?

Rich (BB code):
Sub Copy10()
Dim LR As Long, i As Long, ws As Worksheet
Set ws = ActiveSheet
Worksheets.Add
With ws
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 32 To LR Step 11
        .Range("A" & i).Copy Destination:=Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 36 To LR Step 11
        .Range("C" & i).Copy Destination:=Range("B" & Rows.Count).End(xlUp).Offset(1)
    Next i
End With
End Sub
 
Upvote 0
It doesnt highlight any line just displays the error message and the only option is to click 'ok' or 'help' which direct you to the MS website!
 
Upvote 0
Run this: what message is displayed?

Code:
Sub Copy10()
Dim LR As Long, i As Long, ws As Worksheet
On Error GoTo Alert
Set ws = ActiveSheet
Worksheets.Add
With ws
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 32 To LR Step 11
        .Range("A" & i).Copy Destination:=Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 36 To LR Step 11
        .Range("C" & i).Copy Destination:=Range("B" & Rows.Count).End(xlUp).Offset(1)
    Next i
End With
Exit Sub
Alert:
MsgBox Err.Description
End Sub
 
Upvote 0
back in business, thank you very much from a very stressed phd student handing in in 2 weeks!!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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