Having A lot of toruble with a Macro

nathan663

Board Regular
Joined
Dec 3, 2008
Messages
153
I have a spreadsheet that is basically a questionnaire. I have created a macro that takes certain answers from the questionnaire and puts them in a second spreadsheet but in a row.

However i need the macro to start again on the next available row. At the moment each time you run the macro it will just insert the data, over the cells already completed. (It will only put the data taken from the questionnaire on the row i set the macro up for.)

I need to add something to my macro in order to tell it to start on the next available row so i can use the macro over and over and keep all previous data.

Surely there must be a simple code to add to the beggining of the macro???
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You need to make the row number dynamic so it changes as the sheet updates. If you always have data Column A, this will put the data in the next available row.

finalrow = Cells(65536, 1).End(xlUp).Row
Answer = Cells(finalrow, 1).Value
 
Upvote 0
It would help if we could see the code otherwise we have no idea what you are already doing?
 
Upvote 0
this is a draft of the code, only taking a few cells from the questionnaire, please note that there will be different marcos for different types of questionnaire (all still being put in row form on the second spreadsheet) So i need something i can add to each to make them start on the next available row

this is really driving me mad!

Sub Button40_Click()
'
' Button40_Click Macro
' Macro recorded 25/03/2009 by Nathan Gallichan
'
'
Range("L22").Select
Selection.Copy
Windows("Book4").Activate
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
Range("L23").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book4").Activate
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
Range("L24").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book4").Activate
Range("C2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
Range("L25").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book4").Activate
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
Range("L26").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book4").Activate
Range("E2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
Range("L27").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book4").Activate
Range("F2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
 
Upvote 0
As an example replace

Code:
Range("L22").Select
Selection.Copy
Windows("Book4").Activate
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

with

Code:
Range("L22").Copy
Windows("Book4").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Your code is asking for trouble with this part:

Code:
Range("L22").Select
    Selection.Copy
Windows("Book4").Activate
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

and this part

Code:
Windows("New Accounts - KYC Checklists - Jersey new world 2009.xls").Activate
    Range("L23").Select
    Application.CutCopyMode = False
    Selection.Copy

A better idea would be to use workbook and worksheet names. Using select is not required either.

To help you further please post:

1) The worksheet you are using in: New Accounts - KYC Checklists - Jersey new world 2009.xls

2) The worksheet you are using in: Book4
 
Upvote 0
Or just taking Vog's example a step further, replace all your code with:
Code:
Range("L22:L27").Copy
Windows("Book4").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False
[/quote]

But the code would be better off without the "Windows" part and the "Activate" part.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,081
Messages
6,053,416
Members
444,662
Latest member
AaronPMH

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