Unable to copy data from one Excel sheet to another when not copying to column A

Nothemattic

I have this code:

Sub Button26_Click()
Dim s1, s2

    Set s1 = Worksheets("Invoice Generator")
    Set s2 = Worksheets("Past Invoices")

    With s2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).EntireRow
        .Cells(, "a").Value = s1.Range("f27").Value
    End With
End Sub

To copy the cell f27 (initially) from sheet one to sheet two (on a new row each time) when the button is clicked. However, if I change "a" to any other cell reference then the data only gets copied once - subsequent clicks do not work.

Anyone have any ideas? Thanks.

user4039065

You are setting the position by starting at the bottom of column A and looking up to the first non-blank cell then offsetting down one row to a blank cell. If you take this position but stuff values into the row starting at column B, you never fill that empty cell in column A so subsequent calls to the same routine will reposition to exactly the same spot. If you are going to use column B as the target, you need to position the new transfer of values based on the first blank cell in columns B, not column A.

Dim targetCOL as long
targetCOL = 2
With s2.Cells(Rows.Count, targetCOL).End(xlUp).Offset(1, 0).EntireRow
    .Cells(, targetCOL).Value = s1.Range("f27").Value
End With

Since you have to change the column of both the positioning method and the target of the values it makes sense to put either the alphabetic columns reference or the numerical column index into a variable so that changing it there will change it in both required places. In the above suggested modification, I've used the column's numerical index to set column B.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Unable to copy all data in column to another sheet - excel VBA

分類Dev

Copy rows of data to another sheet in Excel and add column VBA

分類Dev

How to copy only formulas from one excel sheet which can dynamically grow to another sheet using macro

分類Dev

Need a script to transfer data from one excel sheet to another

分類Dev

Copy data from one sheet's cell to multiple cells in another sheet

分類Dev

Copying row info from one sheet to another, based on cell input

分類Dev

Copying cell from one sheet to another without formatting

分類Dev

Script for condition based copy cells from one sheet to another sheet

分類Dev

Copy data one excel to another excel

分類Dev

EXCEL VBA: Copy Sheet from a workbook to another workbook in different location

分類Dev

Proc sql: Creating a view by copying data from one year to another

分類Dev

Copying data from one table to another using php mysqli fails

分類Dev

How to copy one column data into another column in oracle

分類Dev

How to copy the values in a range from one sheet to and paste it another sheet on a predefied order using VBA?

分類Dev

Moving data from one sheet to another via a hyperlink

分類Dev

Copy values from one column to another using Pandas

分類Dev

Copy value from one column to another based on condition (using pandas)

分類Dev

How to populate or update column value in an excel sheet based on data values in another reference column

分類Dev

Copying words from one file to another in cpp

分類Dev

Copying properties from one object to another with a condition

分類Dev

Copying elements from one character array to another

分類Dev

copying files from one directory to another

分類Dev

Oracle 11g: copying a column from one table to another adding an sequence ID. Dropping a sequence

分類Dev

How to copy data from a column to another based on a condition in R?

分類Dev

Copying text from file to specified Excel column

分類Dev

VBA Script copied from one Sheet to Another

分類Dev

Copy spreadsheet sheet to a another one with Google API using Python

分類Dev

How to populate array from a sheet column in Excel

分類Dev

Passing data from one fragment to another is not working when passing data

Related 関連記事

  1. 1

    Unable to copy all data in column to another sheet - excel VBA

  2. 2

    Copy rows of data to another sheet in Excel and add column VBA

  3. 3

    How to copy only formulas from one excel sheet which can dynamically grow to another sheet using macro

  4. 4

    Need a script to transfer data from one excel sheet to another

  5. 5

    Copy data from one sheet's cell to multiple cells in another sheet

  6. 6

    Copying row info from one sheet to another, based on cell input

  7. 7

    Copying cell from one sheet to another without formatting

  8. 8

    Script for condition based copy cells from one sheet to another sheet

  9. 9

    Copy data one excel to another excel

  10. 10

    EXCEL VBA: Copy Sheet from a workbook to another workbook in different location

  11. 11

    Proc sql: Creating a view by copying data from one year to another

  12. 12

    Copying data from one table to another using php mysqli fails

  13. 13

    How to copy one column data into another column in oracle

  14. 14

    How to copy the values in a range from one sheet to and paste it another sheet on a predefied order using VBA?

  15. 15

    Moving data from one sheet to another via a hyperlink

  16. 16

    Copy values from one column to another using Pandas

  17. 17

    Copy value from one column to another based on condition (using pandas)

  18. 18

    How to populate or update column value in an excel sheet based on data values in another reference column

  19. 19

    Copying words from one file to another in cpp

  20. 20

    Copying properties from one object to another with a condition

  21. 21

    Copying elements from one character array to another

  22. 22

    copying files from one directory to another

  23. 23

    Oracle 11g: copying a column from one table to another adding an sequence ID. Dropping a sequence

  24. 24

    How to copy data from a column to another based on a condition in R?

  25. 25

    Copying text from file to specified Excel column

  26. 26

    VBA Script copied from one Sheet to Another

  27. 27

    Copy spreadsheet sheet to a another one with Google API using Python

  28. 28

    How to populate array from a sheet column in Excel

  29. 29

    Passing data from one fragment to another is not working when passing data

ホットタグ

アーカイブ