简体   繁体   中英

excel VB copy cells from on sheet to another

I´m having problems with my code I want this code to copy cells from one sheet to another but with the following trick (english is not my first language, Sorry )

In "sheet1" there is "date and ticket number" always in the same cell, but I also want to copy a list of values that can change in amount...(A10) all these values go to "sheet2" in the same row... "date1" "ticket123" "itemA" "amount" "date1" "ticket123" "itemB" "amount2"

Private Sub CommandButton1_Click()

filalibre = Sheets("sheet2").Range("a1048576").End(xlUp).Row + 1
ActiveSheet.Range("a10").Select
fila = 10

While ActiveCell.Value <> ""
Sheets("sheet2").Cells(filalibre, 1) = ActiveSheet.Range("E4") 
Sheets("sheet2").Cells(filalibre, 2) = ActiveSheet.Range("E2") 

Sheets("sheet2").Cells(filalibre, 3) = ActiveSheet.Offset(0, 0) 
Sheets("sheet2").Cells(filalibre, 4) = ActiveSheet.Offset(0, 1) 


filalibre = filalibre + 1

ActiveCell.Offset(1, 0).Select
Wend
Call limpieza
End Sub

What can I read to fix this... or can anyone help me

Since you have not mentioned the exact problem or the error you see, I can see some possible sources of an issue.

Replace

Sheets("sheet2").Cells(filalibre, 3) = ActiveSheet.Offset(0, 0) 
Sheets("sheet2").Cells(filalibre, 4) = ActiveSheet.Offset(0, 1)

By

Sheets("sheet2").Cells(filalibre, 3) = ActiveCell.Offset(0, 0) 
Sheets("sheet2").Cells(filalibre, 4) = ActiveCell.Offset(0, 1)

Besides this,there are a few other improvements that can be done to your code. But first try to get it working without an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM