473,499 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access copy/paste special

10 New Member
I've run my queries in Access VBA and exported data into excel. I want to select Range("A4:AC4") (which are formulas reading from data just exported) and paste/values/formatting appending to bottom of same sheet. How do I find the bottom of data and place on next row.

Expand|Select|Wrap|Line Numbers
  1. Public Sub TEST()
  2.  
  3. Dim locationstring7 As String
  4.  
  5. locationstring7 = "J:\Reports.xlsx"
  6.  
  7.  
  8. DoCmd.OpenQuery "QryMakeLoadID"
  9. DoCmd.Close acQuery, "QryMakeLoadID"
  10. DoCmd.OpenQuery "QryMakeLocAvailable"
  11. DoCmd.Close acQuery, "QryMakeLocAvailable"
  12.  
  13. Set dbs = CurrentDb
  14. Set rsQuery = dbs.OpenRecordset("QryCapacityReport")
  15. Set excelapp = CreateObject("Excel.application", "")
  16.  
  17. excelapp.Visible = True
  18. Set TargetWorkbook = excelapp.Workbooks.Open("J:\Reports")
  19.  
  20. TargetWorkbook.Worksheets("data").Range("A3", "K8000").Clear
  21. TargetWorkbook.Worksheets("data").Range("A3").CopyFromRecordset rsQuery
  22.  
  23.  
  24. TargetWorkbook.Worksheets("Daily Summary").Range("A4:AC4").Copy
  25. TargetWorkbook.Worksheets("Daily Summary").[A1].Select
  26.  
  27.  
  28. TargetWorkbook.Worksheets("Daily Summary").Cells("A1107").paste  
  29.  
  30. TargetWorkbook.Save
  31. excelapp.Quit
  32.  
  33.  
  34. End Sub
May 1 '20 #1
8 3921
NeoPa
32,557 Recognized Expert Moderator MVP
The Ctrl-End key combination puts you at the end (Bottom-Right) of the used range of cells. In Excel VBA this can be referenced using the SpecialCells(xlLastCell) method. I assume, from what you've said, that you would like to start in column A but from the Row starting immediately after the last used row.

That would be something like :
Expand|Select|Wrap|Line Numbers
  1. Range("A" & ActiveCell.SpecialCells(xlLastCell).Row + 1)
SpecialCells(xlLastCell) is a method of the Range class so needs a Range object to be called within, but the Range doesn't seem to matter or affect the result. ActiveCell is merely an example in this case.
May 2 '20 #2
kommanman
10 New Member
Compile error: Sub or Function not defined.
May 4 '20 #3
NeoPa
32,557 Recognized Expert Moderator MVP
Kommanman:
Compile error: Sub or Function not defined.
What have you tried (not very hard) to tell me?

I'm not too impressed that you've saved yourself the effort of writing much while leaving us working to try to understand what you mean :-(
May 5 '20 #4
kommanman
10 New Member
I apologize for lack of details but I have been trying many different ways to Paste/special on the last row from internet suggestions.(append new data) This is my first attempt to manipulate data using Access VBA in Excel spreadsheet. Code works fine up to paste. I can copy and paste special.
TargetWorkbook.Worksheets("Daily Summary").range("A1111").pastespecial
but I don't want line "A1111" I need to append and pastespecial paste formulas and I want values/formats.
May 5 '20 #5
kommanman
10 New Member
Microsoft excel object library was not checked. Therefore all 'xl...'commands were not working. After change this worked for me.
Expand|Select|Wrap|Line Numbers
  1. TargetWorkbook.Worksheets("Daily Summary").Range("A100000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
thank you for your help and motivation.
Cheers!!!
May 5 '20 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Ah. It's starting to make more sense now - and by the way I'm pleased and impressed you managed to find the solution without further help.

You've used an alternative technique from the one I illustrated which is equivalent to jumping a long long way down, such that you know you're beyond the bottom of the data, then using Ctrl-Up to find the first cell (going upwards) in that column that contains data and from there going down one row. Complicated - but it works reliably as long as you can be sure the bottom Row of data in that Column will always have data.

Obviously, now we know that you're working on Excel Workbook from within Access code, we could advise about the Reference but you've got there already too. Well done.

Please understand we do try to help but that our ability to do so is heavily dependent on what it is you share with us.
May 5 '20 #7
kommanman
10 New Member
I do understand that this community helps and I'm grateful for all input. I'm used to working alone since I'm an Industrial Engineer and we don't have many friends. haha. Sorry for lack of detail but 'you don't know what you don't know" and I will work on my explanations in the future so as to not frustrate.
Thanks again. Cheers.
May 5 '20 #8
NeoPa
32,557 Recognized Expert Moderator MVP
My intention explaining that is to allow you to perceive, not only how important it is for us, but also how important it is for you. The amount of time & effort you will save yourself is also considerable. Sure, it requires a little effort up front, but I don't recall many situations where the OP didn't end up having to put the effort in eventually anyway, and so just ended up with unnecessary delays (Compared to getting answers quickly when all the relevant details are known).

So, I have no wish to get on your back. Just to help you help yourself. Oh, and you're absolutely right about not knowing what you don't know. That comes up a lot. If you think about it though, you generally find you know at least a little more than you thought you did.

Anyway - I'm in danger of lecturing again so I'll stop there with the hope that we are able to help again in the future.
May 5 '20 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2717
by: Bani | last post by:
Is it possible to get browser-menu events (IE) into Javascript? I have a special copy/paste on the onkeydown event (ctrl+c/ctrl+v). Now the users would like to trigger it also from the browser...
1
2542
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
1
2720
by: PaulMac | last post by:
I need to be able to copy and paste the contents of an HTML page into a field in my adp. Is this even possible? In Word I can click Paste Special, and select HTML and it copies the table just as it...
4
21588
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
7
11597
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
8
2595
by: serge calderara | last post by:
Dear all, I have an treeview control with different node object, I would like to implement the Copy/Paste function of an object . For that I am using the folowing function to copy teh object to...
0
7247
by: shantanu | last post by:
I am trying to convert a macro code to c# that will copy the values of a column and paste to anather through paste special. Everything is working fine but the transpose meathod to paste the column...
1
6800
by: christianlott1 | last post by:
I want to copy an Access pivot table into word with vba. I'm guessing I'd need to Select All, copy to the clipboard, and paste special into word at a bookmark. I know how to address the...
8
15389
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
3
2277
by: Shepard | last post by:
Hi guys, I am developing an application which takes consumer_id from our employees and searches them from database if consumer_id match is found his details are available... Now I have managed to...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.