Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10
Default VBA copy cell to another worksheet

Hello, I am trying to copy text information from one worksheet to
another.
I open only the first sheet then I have a comand button by where I
want to say transfer the values.

La macro give an error at ObjWorshett.Cells(Riga, 1).text =
oDO.GetText
Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
Thanks in advance!
Franco



Dim oDO As New DataObject
oDO.SetText [B2].Value
oDO.PutInClipboard

Dim ObjWorshett As Worksheet
Dim strNomeFile As String

strNomeFile = "\\srv01\Dp\ANTONELLA\sblocco.xls"
Set ObjWorshett = Application.Workbooks.Open(strNomeFile, False,
True).Sheets(1)
UltimaRiga = ObjWorshett.Range("A65356").End(xlUp).Row
Riga = UltimaRiga + 1

oDO.GetFromClipboard
ObjWorshett.Cells(Riga, 1).text = oDO.GetText
Set oDO = Nothing

ObjWorshett.Application.ActiveWorkbook.Close
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,203
Default VBA copy cell to another worksheet

I hope I have understood your needs and that this helps you. I don't believe
you need to use the clipboard for this. You can copy the value in cell B2 on
the active sheet (the one with the command button on it) and place it into
the other workbook.

Also, you were opening the sblocco.xls workbook as Read Only which means you
could not save the change you make to it. I have changed that.

Sub CopyCellValue()
Dim ObjWorshett As Worksheet
Dim strNomeFile As String
Dim UltimaRiga As Long
Dim Riga As Long

' new variables used
Dim objWorkbook As Workbook
Dim valueFromThisWorkbook As Variant

'get the value in Cell B2 on the sheet
'that is active in this workbook
valueFromThisWorkbook = ActiveSheet.Range("B2").Value

strNomeFile = "\\srv01\Dp\ANTONELLA\sblocco.xls"

'open the other workbook, do not update links, _
do NOT open as read only
Set objWorkbook = Workbooks.Open(strNomeFile, False, False)
Set ObjWorshett = objWorkbook.Sheets(1)

UltimaRiga = ObjWorshett.Range("A" & Rows.Count).End(xlUp).Row
Riga = UltimaRiga + 1
'if you do not need UltimaRiga later, you can rewrite those
'two statements as one:
' Riga = ObjWorshett.Range("A" & Rows.Count).End(xlUp).Row + 1

ObjWorshett.Cells(Riga, 1).Value = valueFromThisWorkbook
Set ObjWorshett = Nothing
objWorkbook.Close True ' close and save changes
Set objWorkbook = Nothing
End Sub


"franco monte" wrote:

Hello, I am trying to copy text information from one worksheet to
another.
I open only the first sheet then I have a comand button by where I
want to say transfer the values.

La macro give an error at ObjWorshett.Cells(Riga, 1).text =
oDO.GetText
Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
Thanks in advance!
Franco



Dim oDO As New DataObject
oDO.SetText [B2].Value
oDO.PutInClipboard

Dim ObjWorshett As Worksheet
Dim strNomeFile As String

strNomeFile = "\\srv01\Dp\ANTONELLA\sblocco.xls"
Set ObjWorshett = Application.Workbooks.Open(strNomeFile, False,
True).Sheets(1)
UltimaRiga = ObjWorshett.Range("A65356").End(xlUp).Row
Riga = UltimaRiga + 1

oDO.GetFromClipboard
ObjWorshett.Cells(Riga, 1).text = oDO.GetText
Set oDO = Nothing

ObjWorshett.Application.ActiveWorkbook.Close
.

  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10
Default VBA copy cell to another worksheet

Thanks JLatham, it's exactly that I want!
But on the line -- Set objWorkbook = Workbooks.Open(strNomeFile,
False, False)
I have the same error:
Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
I'm searching for on the net but Your help is appreciated!
Thanks again
  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,203
Default VBA copy cell to another worksheet

It works properly for me under several tests. So we need to focus in on what
part of the command is not working properly.

Set up some test code and see if it works:

Sub TestFileOpen()
Workbooks.Open("\\srv01\Dp\ANTONELLA\sblocco.xls")
End Sub

If that does not work properly, check to be certain that the path to the
file is correct.

If that does work, then change the code and test again:
Sub TestFileOpen()
Workbooks.Open("\\srv01\Dp\ANTONELLA\sblocco.xls", False, False)
End Sub

And if that also works properly, test a little mo
Sub TestFileOpen()
Dim strNomeFile As String

strNomeFile = "\\srv01\Dp\ANTONELLA\sblocco.xls"
Workbooks.Open(strNomeFile, False, False)
End Sub

and once more, if that succeeds, move on to another test
Sub TestFileOpen()
Dim objWorkbook As Workbook
Dim strNomeFile As String

strNomeFile = "\\srv01\Dp\ANTONELLA\sblocco.xls"
Workbooks.Open(strNomeFile, False, False)
Set objWorkbook = Workbooks(ActiveWorkbook.Name)
ThisWorkbook.Activate
End Sub


"franco monte" wrote:

Thanks JLatham, it's exactly that I want!
But on the line -- Set objWorkbook = Workbooks.Open(strNomeFile,
False, False)
I have the same error:
Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
I'm searching for on the net but Your help is appreciated!
Thanks again
.

  #5   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10
Default VBA copy cell to another worksheet

Thanks JLatham, now it's work correct! Thanks again!!!!

Private Sub Memorizza_Click()
Dim ObjWorshett As Worksheet
Dim strNomeFile As String
Dim UltimaRiga As Long
Dim Riga As Long

' new variables used
Dim objWorkbook As Workbook
Dim valueFromThisWorkbook As Variant

Application.ScreenUpdating = False ' Lavora in background

valueB2 = ActiveSheet.Range("B2").Value 'Agente
' ....

strNomeFile = "\\srv01\Dp\ANTONELLA\Lista sblocco ordini.xls"

'open the other workbook, do not update links, _
do NOT open as read only
Set objWorkbook = Workbooks.Open(strNomeFile, False, False)
Set ObjWorshett = objWorkbook.Sheets(1)

UltimaRiga = ObjWorshett.Range("A" & Rows.Count).End(xlUp).Row
Riga = UltimaRiga + 1

ObjWorshett.Cells(Riga, 1).Value = valueB2 'Agente
' ....

Set ObjWorshett = Nothing
objWorkbook.Close True ' close and save changes
Set objWorkbook = Nothing
Application.ScreenUpdating = True ' Fine Lavora in background
End Sub


  #6   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,203
Default VBA copy cell to another worksheet

Good to hear that. Glad I could help.

"franco monte" wrote:

Thanks JLatham, now it's work correct! Thanks again!!!!

Private Sub Memorizza_Click()
Dim ObjWorshett As Worksheet
Dim strNomeFile As String
Dim UltimaRiga As Long
Dim Riga As Long

' new variables used
Dim objWorkbook As Workbook
Dim valueFromThisWorkbook As Variant

Application.ScreenUpdating = False ' Lavora in background

valueB2 = ActiveSheet.Range("B2").Value 'Agente
' ....

strNomeFile = "\\srv01\Dp\ANTONELLA\Lista sblocco ordini.xls"

'open the other workbook, do not update links, _
do NOT open as read only
Set objWorkbook = Workbooks.Open(strNomeFile, False, False)
Set ObjWorshett = objWorkbook.Sheets(1)

UltimaRiga = ObjWorshett.Range("A" & Rows.Count).End(xlUp).Row
Riga = UltimaRiga + 1

ObjWorshett.Cells(Riga, 1).Value = valueB2 'Agente
' ....

Set ObjWorshett = Nothing
objWorkbook.Close True ' close and save changes
Set objWorkbook = Nothing
Application.ScreenUpdating = True ' Fine Lavora in background
End Sub
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy cell from one worksheet to another worksheet in exel luvs_choc8 Excel Discussion (Misc queries) 1 July 10th 07 04:16 PM
copy data in a cell from worksheet A to worksheet B rajesh Excel Discussion (Misc queries) 1 February 21st 06 07:40 AM
How do I copy a date in a worksheet cell to another worksheet? JennLee Excel Worksheet Functions 3 February 17th 06 05:38 PM
How do I copy a cell from one worksheet to another worksheet skywriter Excel Discussion (Misc queries) 1 November 18th 05 10:20 AM
how do I copy the worksheet tab name to a cell? shoshaw Excel Discussion (Misc queries) 2 February 1st 05 09:12 AM


All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"