PDA

View Full Version : Solved: Copy Macro that Won't Copy :(



Phelony
07-15-2009, 03:05 AM
Hi guys

Yet again, I've managed to break something really simple and don't quite understand why. :mkay

The below is supposed to open an input box, get a number, stash the number in cell M1, exit the sub if you click cancel and then copy 50 rows and 13 columns beneath the same depending on the input number, less 1 as the information already on screen counts as 1.

It's done it once, then I had to add the vbcancel part and it's stopped working.....:banghead:

Could I please borrow someones superior knowledge of such things to tell me how I've killed it?

Sub Moreaccounts()
'
' Moreaccounts Macro

Sheets("NCA A Page 2").Select
Answer = InputBox("How many accounts do you require in total?")
Range("M1") = Answer

If vbCancel Then Exit Sub

Dim t As Long
For t = 1 To Range("M1").Value - 1
With Range("A1")

.Resize(51, 13).Copy .Offset(t * 50 + 0, 0)
End With
Next t
End Sub

I'm sure there's nothing overtly complicated here, but I've been messing with it for a while now and it's just annoying. :motz2:

:help

Phel x

JimmyTheHand
07-15-2009, 03:51 AM
Maybe
Sub Moreaccounts()
'
' Moreaccounts Macro
Dim t As Long , Answer
Sheets("NCA A Page 2").Select
Answer = InputBox("How many accounts do you require in total?")
Range("M1") = Answer
If Answer = "" Then Exit Sub

For t = 1 To Range("M1").Value - 1
With Range("A1")
.Resize(51, 13).Copy .Offset(t * 50 + 0, 0)
End With
Next t
End Sub

mdmackillop
07-15-2009, 03:54 AM
Remember to use Option Explicit


If answer = vbCancel Then Exit Sub

Phelony
07-15-2009, 03:56 AM
Thank you gentlemen for two very helpful responses. :bow:

It's always the little things.