Compile error copying cells - VB

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

I'm getting a compile error when trying to copy cells in column G from row 4 to end to, column H from row 5 to end.

I set HBParmTC1 to "H5", HBParmTC2 to "H", ParmTC1 to "G4", ParmTC2 to "G"

Any help would be great...

Sheets("Parms").Range(HBParmTC1, .Range(HBParmTC2 & Rows.Count).End(xlUp)) _
.Copy Destination:=ThisWorkbook.Sheets("Parms").Range(ParmTC1, .Range(ParmTC2 & Rows.Count).End(xlUp))

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Are all those variables strings?
 
Upvote 0
Hi Nori,

Yes, they are strings.

Public ParmTC1 As String
Public ParmTC2 As String
Public HBParmTC1 As String
Public HBParmTC2 As String

After my first post, I realized that I had the variables reversed. HBParm variables needed to be my destination. I made the change and still recieved the compile error.

Sheets("Parms").Range(ParmTC1, .Range(ParmTC2 & Rows.Count).End(xlUp)) _
.Copy Destination:=ThisWorkbook.Sheets("Parms").Range(HBParmTC1, .Range(HBParmTC2 & Rows.Count).End(xlUp))

Thanks so much, Nori, for your help
 
Upvote 0
Hi Nori,

I'm not sure my 2nd Post regsitered. I should she a total of 3 posts but only shows 2, my original and your response. My laptop froze when I was paosting my reply to your posts. Making sure that you get this... Thanks
 
Upvote 0
I don't think it's anything to do with the order.

Is there any other code, in particular a With <worksheet> type statement?

If you don't then something like this won't work.
Code:
.Range(ParmTC2 & Rows.Count).End(xlUp)
If you do it still might not work.

Which worksheets are you copying to/from or is the whole thing being done with the same worksheet?

If it's the same worksheet you could try something like this.
Code:
Set wsSrc = Worksheets("Parms")
 
LastRowSrc = wsSrc.Range("G"& Rows.Count).End(xlUp).Row
 
Set rngSrc = wsSrc.Range("G5:G" & LastRowSrc)
 
Set wsDst = Worksheets("Parms")
 
Set rngDst = wsDst.Range("H4")
 
rngSrc.Copy rngDst
I know that code probably isn't quite right, it's more of an example of another approach you could use..

It's a bit more code but, to me anyway, it's easier to follow and therefore easier to spot errors or alter.:)

PS You could still use your variables in that code, I left them out because I wasn't 100% sure if I was quite getting them.
 
Upvote 0
Thanks so much Nori...

I'm having a difficult time selecting cells not sequential in a column for deletion. As soon as I get this resolved, I'll give the copy routine a shot.

Thanks again...
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,287
Members
449,218
Latest member
Excel Master

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