exele
08-03-2014, 10:47 PM
Hi,
I found the code below from this forum. The thread was about extracting data from one sheet to another and the code should work so that when you click the commandbutton, the values from row 1 in sheet1 should be copied to the sheet2. My button is however copying only values of "0". So if I have in my sheet1 in cell A1 =H10 and in H10 is value 500, the code copies "0" instead of "500". On the previous thread there were no comments about any problems, so the code should work fine but it just isn't?
I also have another question - could this be modified so that the values could be located in row 10 for instance, instead of row1?
Private Sub CommandButton1_Click()
Dim Lastrow As Long
With Worksheets("Sheet2")
If .Range("A1").Value = "" Then
Lastrow = 1
Else
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End If
Rows(1).Copy .Cells(Lastrow, "A")
.Rows(Lastrow).Value = .Rows(Lastrow).Value
End With
End Sub
I found the code below from this forum. The thread was about extracting data from one sheet to another and the code should work so that when you click the commandbutton, the values from row 1 in sheet1 should be copied to the sheet2. My button is however copying only values of "0". So if I have in my sheet1 in cell A1 =H10 and in H10 is value 500, the code copies "0" instead of "500". On the previous thread there were no comments about any problems, so the code should work fine but it just isn't?
I also have another question - could this be modified so that the values could be located in row 10 for instance, instead of row1?
Private Sub CommandButton1_Click()
Dim Lastrow As Long
With Worksheets("Sheet2")
If .Range("A1").Value = "" Then
Lastrow = 1
Else
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End If
Rows(1).Copy .Cells(Lastrow, "A")
.Rows(Lastrow).Value = .Rows(Lastrow).Value
End With
End Sub