Full Version: sharing information between worksheets
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
brh
I have a few boxes in "sheet 1" that I'd like to have auto fill in "sheet 2". is there an easy way to do this?
KingMartin
Hello,
which kind of box? Combo?

This code when put into first sheet's class module will write the value to A1 of the second sheet:
CODE
Private Sub ComboBox1_Change()
Sheets(2).[a1] = ComboBox1
End Sub

Martin
brh
Sorry no..Their just "cells" w/ stuff like hours, dates.. stuff like that...Will your code work with a cell too? exactly where would I place this code?
Thanks for the help.
Brian
KingMartin
OK, in general, this will write values from one sheet to another:

CODE
Sub test()
Set srcSht = Sheets("Sheet1")
Set tgtSht = Sheets("Sheet2")

'will copy A1 to A1
tgtSht.[a1] = srcSht.[a1]

'will copy data in column A  to column C
tgtSht.Range("C1:C" & srcSht.[a65536].End(3).Row) = _
    srcSht.Range("A1:A" & srcSht.[a65536].End(3).Row).Value
End Sub


Hit Alt + F11, Insert => Module paste the code there and experiment with it.

Hope this helps for the start
Martin
brh
this worked on a blank form...

Sub test()
Set srcSht = Sheets("Sheet1")
Set tgtSht = Sheets("Sheet2")
'will copy A1 to A1
tgtSht.[N1] = srcSht.[L1]
End Sub

but not on my workbook.

I get a runtime error 9

any ideas... did I enter this wrong?

thanks
Brian
KingMartin
Maybe your sheets have different names?i
brh
You're right! smile.gif thanks again
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.