Range("A1").End(xlDown).Offset(1, 0).Select

Daburger

New Member
Joined
Jul 15, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a case/call audit sheet in which I am trying to move the data between other sheets, yet having no luck.
I keep getting the Run-time error'1004': Application-defined or object-defined error.

When I debug, it highlights the following line: Range("A1").End(xlDown).Offset(1, 0).Select

VBA Code:
Sub add_record()

    Sheets("Temp Data").Select
    Range("A2:BJ2").Select
    Selection.Copy
    Sheets("Case-Call RAW Data").Select
    Range("A1").End(xlDown).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Case-Call Audit").Select

End Sub

Any help as always will be greatly appreciated!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you have nothing in column A, then Range("A1").End(xlDown) will be the last cell in column A, and .Offset(1) will take you off the end of the column, hence the error.

You don't need all the .Selects. Try:

VBA Code:
Sheets("Temp Data").Range("A2:BJ2").Copy
Sheets("Case-Call RAW Data").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
If you have nothing in column A, then Range("A1").End(xlDown) will be the last cell in column A, and .Offset(1) will take you off the end of the column, hence the error.

You don't need all the .Selects. Try:

VBA Code:
Sheets("Temp Data").Range("A2:BJ2").Copy
Sheets("Case-Call RAW Data").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
Instead of

Try
Thanks to both of you for your help. I really do appreciate it.
Both worked to a degree....but not completely.
Crystalyzer - I had tried this previously but forgot to mention this before. my apologies.
I will explain a little more detail below:

The story behind the macro:
I have data that I input on a sheet called "Case-Call Audit".
Think of it as just a call audit sheet. It has around 20 questions such as: did the person do XYZ?
If yes, I populate the "yes" column with a 1 for that question.
If no, I leave the "yes" column blank and populate the "no" column with a 1.
If not applicable, I leave both "yes and no" columns and populate the "N/A' column with a 1.
At the end of the audit, it calculates all the populated fields and gives a percentage which is the final score.

So the point of the macro is that it is meant to copy the data from this "Case-Call Audit" sheet and then paste it into sheet "Temp Data".
From "Temp Data", it copy's the newly pasted data and pastes it into "Case-Call RAW Data".

The "Temp Data" sheet only ever holds the most recent audit that I want to upload...nothing more.
The "Case-Call RAW Data" stores all audits that I have entered and then run the macro for.

Both your codes do work as far as adding whatever data is in the "Temp Data" sheet and then pastes it into the raw data. This is great, providing if there is data in there to copy.
The problem is I need to populate the "Temp Data" sheet from the "Case-Call Audit" first before copying any cells and pasting them into the "Case-Call Raw Data" sheet.
This is where I am currently at now.

This workbook was given to me by a friend of mine and it WAS working for him.
He has this code running for two lots of different audits, each going to their own temp data sheets and raw data sheets, etc.
One actually still works but the other one doesn't. Both use the exact same code (other than using different worksheets etc).
So the original code I have should work, but cannot figure out what on earth is causing it not to work.

I know all the cells match, the names match, etc. just cannot figure it out.
 
Upvote 0
It looks like this distils down to ...

- The problem lies with some other code (not posted) which is supposed to copy data from "Case-Call Audit" to "Temp Data"
- That code isn't copying any data?

Can your post your complete code?
 
Upvote 0
Can you post all the worksheets with the XL2BB tool? I'm afraid without that I won't be able to continue to assist troubleshooting.
 
Upvote 0
Hi @StephenCrump and @Crystalyzer,

The full code is mentioned in my first post above. Unfortunately, there is no other code.
I must also say, the other sheet where the above original code worked, was a much simpler sheet without each "section"...there was only 1 section.
This could explain why it isn't working...my apologies if this made it confusing.

My apologies again if what I am saying does not make much sense. I am still learning VBA code and is taking me a long time to get a grasp of it. I am very much an amateur here.
I have now installed XL2BB and have copied the code below as minisheets below:

Case-Call Audit:
Book2.xlsm
ABCDEFGHI
1Call Audit
2Agent:bob
3Channel:phone
4
5Call ID:1122334455
6Call Date:5-11-21 12:00 AM
7Other data 1:
8Other data 2:
9Other data 3:
10Other Data Date:18-May-21
11Audit Date:06-Aug-21
12
13YesNoN/AKPI CategoryKPIScore
14Section 1
15Q11Section 1KPI 11
16Q21Section 1KPI 21
17Q31Section 1KPI 31
18Q41Section 1KPI 40
19Q51Section 1KPI 50
20Q61Section 1KPI 60
21Q71Section 1KPI 71
22Total:430Section 1Total:57.14%
23Score:57.14%
24Section 2
25Q81Section 2KPI 81
26Q91Section 2KPI 91
27Q101Section 2KPI 101
28Q111Section 2KPI 11N/A
29Q121Section 2KPI 120
30Total:311Section 2Total:75.00%
31Score:75.00%
32Section 3
33Q131Section 3KPI 131
34Q141Section 3KPI 141
35Q151Section 3KPI 151
36Q161Section 3KPI 161
37Q171Section 3KPI 171
38Q181Section 3KPI 181
39Q191Section 3KPI 190
40Q201Section 3KPI 201
41Q211Section 3KPI 211
42Q221Section 3KPI 221
43Q231Section 3KPI 231
44Q241Section 3KPI 241
45Q251Section 3KPI 25N/A
46Q261Section 3KPI 261
47Total:1211Section 3Total:92.31%
48Score:92.31%
49Section 4
50Q271Section 4KPI 271
51Q281Section 4KPI 281
52Q291Section 4KPI 291
53Q301Section 4KPI 300
54Q311Section 4KPI 310
55Q321Section 4KPI 320
56Q331Section 4KPI 331
57Q341Section 4KPI 341
58Q351Section 4KPI 350
59Q361Section 4KPI 360
60Q371Section 4KPI 370
61Q381Section 4KPI 38N/A
62Q391Section 4KPI 39N/A
63Q401Section 4KPI 401
64Total:662Section 4Total:50.00%
65Score:50.00%
66Section 5
67Q411Section 5KPI 411
68Q421Section 5KPI 421
69Q431Section 5KPI 431
70Q441Section 5KPI 441
71Q451Section 5KPI 451
72Total:500Section 5Total:100.00%
73Score:100.00%
74
75Overall Total:18103
76Overall Score:64.29%
77Comments:
78
79
80
Case-Call Audit
Cell Formulas
RangeFormula
D22:F22D22=SUM(D15:D21)
I15:I21,I67:I71,I50:I63,I33:I46,I25:I29I15=IF(D15=1,1,IF(E15=1,0,"N/A"))
I22,I72,I64,I47,I30I22=F23
F23,F73,F65,F48,F31F23=D22/(D22+E22)
D72:F72,D30:F30D30=SUM(D25:D29)
D64:F64,D47:F47D47=SUM(D33:D46)
D75:F75E75=SUM(E22,E30,E64,E72)
D76D76=D75/(D75+E75)
Cells with Data Validation
CellAllowCriteria
A1:I80Any value


Temp Data:
- Temp Data sheet is as the name suggests. It stores only the last audit that I previously added. nothing more. This was the way the sheet was given to me. If what I am doing can be done without this...that would be so good!!!
Book2.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJ
1Agent:Channel:Call ID:Call Date:Other data 1:Other data 2:Other data 3:Other Data Date:Audit Date:Issue:KPI 1KPI 2KPI 3KPI 4KPI 5KPI 6Section 1 Total ScoreKPI 7KPI 8KPI 9KPI 10KPI 11Section 2 Total ScoreKPI 12KPI 13KPI 14KPI 15KPI 16KPI 17KPI 18KPI 19KPI 20KPI 21KPI 22KPI 23KPI 24KPI 25Section 3 Total ScoreKPI 26KPI 27KPI 28KPI 29KPI 30KPI 31KPI 32KPI 33KPI 34KPI 35KPI 36KPI 37KPI 38KPI 39Section 4 Total ScoreKPI 40KPI 41KPI 42KPI 43KPI 44Section 5 Total ScoreOverall Total:Overall Score:Comments:
211111
Temp Data


Case-Call RAW Data:
- Case-Call RAW Data has the same fields as Temp data, however, it stores each and every call audit that I add.
Book2.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJ
1Agent:Channel:Call ID:Call Date:Other data 1:Other data 2:Other data 3:Other Data Date:Audit Date:Issue:KPI 1KPI 2KPI 3KPI 4KPI 5KPI 6Section 1 Total ScoreKPI 7KPI 8KPI 9KPI 10KPI 11Section 2 Total ScoreKPI 12KPI 13KPI 14KPI 15KPI 16KPI 17KPI 18KPI 19KPI 20KPI 21KPI 22KPI 23KPI 24KPI 25Section 3 Total ScoreKPI 26KPI 27KPI 28KPI 29KPI 30KPI 31KPI 32KPI 33KPI 34KPI 35KPI 36KPI 37KPI 38KPI 39Section 4 Total ScoreKPI 40KPI 41KPI 42KPI 43KPI 44Section 5 Total ScoreOverall Total:Overall Score:Comments:
2
3
4
Case-Call RAW Data


I hope this helps!
Again, I really do appreciate all the help you are both providing, and anyone else who jumps in to help as well. Greatly appreciated.
 
Upvote 0
As @StephenCrump suggested, the problem is this line because the worksheet Case-Call RAW Data contains NO data past the headers in Row 1. This line causes the code to attempt to select the row directly after the last row in the spreadsheet which cannot be done.

Range("A1").End(xlDown).Offset(1, 0).Select

I've simplified your code to this and it works fine.

VBA Code:
Sub add_record()

    Sheets("Temp Data").Range("A2:BJ2").Copy
    Sheets("Case-Call RAW Data").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Case-Call Audit").Select
 
Upvote 0
Solution
Hi Crystalyzer,

You and @StephenCrump are right and your formula did the trick.
I miss understood beforehand but it has just clicked for me and now your explanations just clicked!!

Thanks again to you both for your time, your explanations, and especially your patience!

Cheers
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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