PDA

View Full Version : Solved: Cell value from cell in different sheet



fredL
02-24-2010, 01:39 AM
Hi everyone,

I've been searching forever to solve this on my own, but I can't seem to find what I'm looking for. I'm pretty sure there's a simple solution, but I just can't find the right piece of code.

The problem:
I have a workbook containing two sheets (sheet1 and sheet2). Basically, I need some cell values from sheet1 to be copied to sheet2, and vice versa.
(I'm attaching a copy of the workbook with some notes in it)

I'll try to clarify what I need:
When the "Get number" button is pressed on sheet1, a new ID number gets written in the next blank cell in column A on sheet2. I've managed to write a code for that

Sub nextfreenumber()

Worksheets("sheet2").Select
Range("A10").End(xlDown).Select
ActiveCell.Offset(1, 0).Select 'Selects the same cell, 1 Row DOWN
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1 'code for value from cell above

End Sub
However, when this macro has been launched and a new number has been added on sheet2, I want the information from sheet1 to be copied to the two cells left of the new number on sheet2, as specified in the workbook.
When all this has been done, sheet1 needs to be selected again.

The ultimate solution would be for all of the cell copying to be done without visibly switching sheets. I don't know if that's possible, but it would certainly look better.

Any help with this is GREATLY appreciated!

/Fred

domfootwear
02-24-2010, 02:24 AM
Hi everyone,

I've been searching forever to solve this on my own, but I can't seem to find what I'm looking for. I'm pretty sure there's a simple solution, but I just can't find the right piece of code.

The problem:
I have a workbook containing two sheets (sheet1 and sheet2). Basically, I need some cell values from sheet1 to be copied to sheet2, and vice versa.
(I'm attaching a copy of the workbook with some notes in it)

I'll try to clarify what I need:
When the "Get number" button is pressed on sheet1, a new ID number gets written in the next blank cell in column A on sheet2. I've managed to write a code for that

Sub nextfreenumber()

Worksheets("sheet2").Select
Range("A10").End(xlDown).Select
ActiveCell.Offset(1, 0).Select 'Selects the same cell, 1 Row DOWN
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1 'code for value from cell above

End Sub
However, when this macro has been launched and a new number has been added on sheet2, I want the information from sheet1 to be copied to the two cells left of the new number on sheet2, as specified in the workbook.
When all this has been done, sheet1 needs to be selected again.

The ultimate solution would be for all of the cell copying to be done without visibly switching sheets. I don't know if that's possible, but it would certainly look better.

Any help with this is GREATLY appreciated!

/Fred

You can try this code:


Sub nextfreenumber()
Worksheets("sheet2").Select
Range("A10").End(xlDown).Select
ActiveCell.Offset(1, 0).Select 'Selects the same cell, 1 Row DOWN
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1 'code for value from cell above
ActiveCell.Offset(0, 1) = "DATE " & Sheets("sheet1").Cells(9, 3) & _
" and " & Sheets("sheet1").Cells(11, 1)
ActiveCell.Offset(0, 2) = "DESCRITPTION 1 " & Sheets("sheet1").Cells(11, 3) & _
" and DESCRITPTION 2 " & Sheets("sheet1").Cells(15, 1)
End Sub

fredL
02-25-2010, 08:39 AM
simple as that. thanks alot domfotwear!