Copy and paste code in VB Excel

Soldato
Joined
18 Oct 2002
Posts
3,074
Location
MK
I want to copy a range of cells from one sheet to another in the same work book.

I found out how to select a range

Application.Goto ActiveWorkbook.Sheets("Total").Range("C2:J3")

But then how do i copy it and paste it into a sheet called Index?

Thanks
 
Something like:
(don't know exactly)

Workbooks(fileyouwanttpasteinto).Activate
ActiveSheet.Paste

Mel P
 
Mel_P said:
Something like:
(don't know exactly)

Workbooks(fileyouwanttpasteinto).Activate
ActiveSheet.Paste

Mel P

you may also want to tpsecify the position where you want paste aswell. Have a look at offsets if u have time, otherwise just activate a cell.
 
That looks better - I haven't used Excel VBA for a while - there are usually several ways of getting to the same endpoint.

mel p
 
In the end, i selected the cells and used the function "Selection.copy"

Found it out by recording the macro and looking at the code :)

Is there a method to select cells with a certain value?

i.e. select all cells in range h5 to al5 with value 1? Then total them?
 
Ok, one more excel question!

How do i do an IF statment on a range of cells?

i.e. IF(a1:a12 = "H", b2 +1)

Comes up with "#value" error :(
 
S@njay said:
Ok, one more excel question!

How do i do an IF statment on a range of cells?

i.e. IF(a1:a12 = "H", b2 +1)

Comes up with "#value" error :(

Something like this?

Code:
=IF(COUNTIF(A1:A12,"=H"), B2+1, 0)
 
Back
Top Bottom