Originally posted by northernladuk
View Post
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: Excel Experts - Stuck Again
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Excel Experts - Stuck Again"
Collapse
-
Originally posted by LisaContractorUmbrella View PostYay - it worked Thank you so much Eek - really appreciated
Leave a comment:
-
Originally posted by eek View PostI think you may need to cut the macro down and work through it step by step as this works
'select the cells we want to copy
Range("a1:b1").Select
Selection.Copy
'move to the worksheet we want the cells on
Sheets("Sheet2").Select
'Move to the correct location on that page (note we only 'want the selected range to be a single cell)
NewCell = Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Range("A" & NewCell).Select
' paste the cells
ActiveSheet.Paste
I wander if you have anything in the clipboard when you get to the paste request.
Leave a comment:
-
Originally posted by LisaContractorUmbrella View PostI know - am trying to get used to 2007 myself. Still didn't work I'm afraid
'select the cells we want to copy
Range("a1:b1").Select
Selection.Copy
'move to the worksheet we want the cells on
Sheets("Sheet2").Select
'Move to the correct location on that page (note we only 'want the selected range to be a single cell)
NewCell = Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Range("A" & NewCell).Select
' paste the cells
ActiveSheet.Paste
I wander if you have anything in the clipboard when you get to the paste request.
Leave a comment:
-
Originally posted by eek View PostI'm not helped by the fact that I only have a very recent version of excel around.
But try changing the paste to be
Range("A1016").Select
Sheets("Daybook Credits").Paste
and see if that allows the paste to work.
Leave a comment:
-
Originally posted by LisaContractorUmbrella View PostHi Eek
Nope no luck unfortunately - came up with same error. The rest of it I have tested and it works ok it's just this last little bit - problem is that the 'cut' area will always be a different size and the 'paste' area will never start in the same cell
But try changing the paste to be
Range("A1016").Select
Sheets("Daybook Credits").Paste
and see if that allows the paste to work.
Leave a comment:
-
Originally posted by eek View PostAs its excel you really only want a single cell to be selected when you hit paste otherwise you can be sure the size of the ranges won't match and you get an error. I would be tempted to try.
Range("A1").Select
ActiveSheet.Paste
I would also say that I don't think that there is a lot of code in that macro that probably won't do what you think it will but that will only be confirmed once you've got the paste working.
Nope no luck unfortunately - came up with same error. The rest of it I have tested and it works ok it's just this last little bit - problem is that the 'cut' area will always be a different size and the 'paste' area will never start in the same cell
Leave a comment:
-
Originally posted by LisaContractorUmbrella View PostHi Eek
Sub Macro1()
Columns("F:F").Select
Selection.Cut Destination:=Columns("N:N")
Range("F1").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[8],LEN(RC[8])-2)"
Range("F1").Select
Selection.AutoFill Destination:=Range("F1:F1015"), Type:=xlFillDefault
Range("F1:F1015").Select
Range("A1").Select
Sheets("Daybook Invoices").Select
Range("A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row).Select
NewCell = Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Range("A" & NewCell).Select
Sheets("Daybook Credits").Select
Range("A1:M1015").Select
ActiveSheet.Paste
End Sub
Comes up with a runtime error 1004 - Paste method of Worksheet class failed. Tricky little blighter!
Any suggestions gratefully received.
Range("A1").Select
ActiveSheet.Paste
I would also say that I don't think that there is a lot of code in that macro that probably won't do what you think it will but that will only be confirmed once you've got the paste working.
Leave a comment:
-
Hi Eek
Thanks for that - we are now ending up in the right place Trouble is the paste is not working - possibly as the data is on a different worksheet. Macro as it stands at the moment is:
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("F:F").Select
Selection.Cut Destination:=Columns("N:N")
Range("F1").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[8],LEN(RC[8])-2)"
Range("F1").Select
Selection.AutoFill Destination:=Range("F1:F1015"), Type:=xlFillDefault
Range("F1:F1015").Select
Range("A1").Select
Sheets("Daybook Invoices").Select
Range("A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row).Select
NewCell = Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Range("A" & NewCell).Select
Sheets("Daybook Credits").Select
Range("A1:M1015").Select
ActiveSheet.Paste
End Sub
Comes up with a runtime error 1004 - Paste method of Worksheet class failed. Tricky little blighter!
Any suggestions gratefully received.
Leave a comment:
-
It gets difficult selecting the cells outside the range as logic is slightly backwards.
From memory its
Range("A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row +1).Select
but its probably better to do something like this as its clearer
NewCell= Cells(Cells.Rows.Count, "A").End(xlUp).Row +1
Range("A" & NewCell).Select
as that is clearer. mind you vba is as clear as mud most of the time.
ActiveSheet.Paste would then paste the contents of the clipboard into the spreadsheet.
Leave a comment:
-
Thanks Tony - this is really useful. Think I am getting there but am having to write the code rather than recording now and it is tricky I have the macro placing the cursor in the correct cell and I have highlighted the area I need from the second worksheet. Trouble is I now don't know how to write the code that will paste it in the area which starts 1 cell down from the last active cell.
Leave a comment:
-
Do this
set a variable for your row number
dim lLastRow as long
use this to determine the last used row
lLastRow = Cells.Find("*",SearchOrder:=xlByRows,SearchDirecti on:=xlPrevious).Row
You can then use this value in any range selection thing
eg range(cells(2,1),cells(llastrow,5)).select
would select cells(2,1) = A_2 to cells(llastrow,5) = e_LastRow
Leave a comment:
-
Originally posted by eek View PostNot an expert but try
Range("A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row).Select
Leave a comment:
-
Thanks for coming back so quickly guys - think a bit more info will help. Two reports are run each week which will have the same number of columns and a different number of rows - both reports are then exported into Excel and fiddled about with until they are in the format that we need.I then need to amalgamate the data on both reports so that the whole lot can be sorted. I want to do all this with a macro as it is a regular excercise and time consuming. Trouble is I can't find a way of automatically directing the cursor to the last row of the first report so that I can copy and paste the data from the second report directly beneath it so that it can be sorted.
Although I am happy to record macros my knowledge of the code is slightly less than would fit on the average size postage stamp but if I have understood correctly the solutions so far would identify the last cell but not take the cursor there
Leave a comment:
-
Not an expert but try
Range("A" & Cells(Cells.Rows.Count, "A").End(xlUp).Row).Select
Leave a comment:
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Five tax return mistakes contractors will make any day now… Today 09:27
- Experts you can trust to deliver UK and global solutions tailored to your needs! Yesterday 15:10
- Business & Personal Protection for Contractors Yesterday 13:58
- ‘Four interest rate cuts in 2025’ not echoed by contractor advisers Yesterday 08:24
- ‘Why Should We Hire You?’ How to answer as an IT contractor Jan 7 09:30
- Even IT contractors connect with 'New Year, New Job.' But… Jan 6 09:28
- Which IT contractor skills will be top five in 2025? Jan 2 09:08
- Secondary NI threshold sinking to £5,000: a limited company director’s explainer Dec 24 09:51
- Reeves sets Spring Statement 2025 for March 26th Dec 23 09:18
- Spot the hidden contractor Dec 20 10:43
Leave a comment: