Find Last Row

VJR

Well-Known Member
Thanks VJ for your response. Its failing again with the same reason.

: Failed to copy worksheet: Exception from HRESULT: 0x800A03EC

(I have found an alternative way of doing it by loading into collection and writing back from collection, but if this code works, it looks neat and it will be useful for others hence trying; much appreciate your time)
The updated code produced the desired output for me with only the values. So need to see where the issue is. It could be on my side too, but can you share what parameters are you passing such that it throws an error.
 
if i change the service to copy and paste in work sheet range with same parameters it works.. so i can confirm parameters are right.
 

VJR

Well-Known Member
This is Sheet 4. Refer formula in C column
View attachment 1535008779677.png

Sheet5 without any data
View attachment 1535008838802.png

Parameters to the new custom action
View attachment 1535008892295.png

Sheet5 after running the new action pasted with only values and without the formula
View attachment 1535008989820.png

Below is the code in the new action

Code:
Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet, source, destination, cells, cell As Object

Try

sw = GetWorkbook(Handle, Source_Workbook)
dw = GetWorkbook(Handle, Destination_Workbook)

ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)
ds = GetWorksheet(Handle, Destination_Workbook, Destination_Worksheet)

sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet
cell = excel.ActiveCell

If Source_Range="" Then
    cells = sheet.Cells
    Destination_Range = "A1"
Else
    cells = sheet.Range(Source_Range)
End If

cells.Select()
source = excel.Selection
source.Copy()
cell.Select()

dw.Activate()
ds.Activate()
sheet = excel.ActiveSheet
cell = excel.ActiveCell
destination = sheet.Range(Destination_Range)
destination.Select()
'sheet.Paste()
destination.PasteSpecial(Paste:=-4163)  '-4163 for xlPasteValues
cell.Select()

My.Computer.Clipboard.Clear()

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    sw = Nothing
    ss = Nothing
    dw = Nothing
    ds = Nothing
    excel = Nothing
    sheet = Nothing
    source = Nothing
    destination = Nothing
    cells = Nothing
    cell = Nothing
End Try
 

VJR

Well-Known Member
Refer the above input, output and code details.
Just make sure it is not throwing the same error from the previous code instance.
Reset, Refresh and Save the Object after the changes are made to it.
 
Thanks VJ.. i get it now.. i had given Sheet.PasteSpecial where as it should be
destination.PasteSpecial(Paste:=-4163)

It works !! thanks a lot for your efforts
 

Rulaxx

New Member
This is Sheet 4. Refer formula in C column
View attachment 1752

Sheet5 without any data
View attachment 1753

Parameters to the new custom action
View attachment 1754

Sheet5 after running the new action pasted with only values and without the formula
View attachment 1755

Below is the code in the new action

Code:
Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet, source, destination, cells, cell As Object

Try

sw = GetWorkbook(Handle, Source_Workbook)
dw = GetWorkbook(Handle, Destination_Workbook)

ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)
ds = GetWorksheet(Handle, Destination_Workbook, Destination_Worksheet)

sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet
cell = excel.ActiveCell

If Source_Range="" Then
    cells = sheet.Cells
    Destination_Range = "A1"
Else
    cells = sheet.Range(Source_Range)
End If

cells.Select()
source = excel.Selection
source.Copy()
cell.Select()

dw.Activate()
ds.Activate()
sheet = excel.ActiveSheet
cell = excel.ActiveCell
destination = sheet.Range(Destination_Range)
destination.Select()
'sheet.Paste()
destination.PasteSpecial(Paste:=-4163)  '-4163 for xlPasteValues
cell.Select()

My.Computer.Clipboard.Clear()

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    sw = Nothing
    ss = Nothing
    dw = Nothing
    ds = Nothing
    excel = Nothing
    sheet = Nothing
    source = Nothing
    destination = Nothing
    cells = Nothing
    cell = Nothing
End Try

Hello VGR I get the next error ": Failed to copy worksheet: The given key was not present in the dictionary."
 

VJR

Well-Known Member
Hello VGR I get the next error ": Failed to copy worksheet: The given key was not present in the dictionary."
The dictionary key error generally appears when the parameters either input or output or both are not correctly generated from its corresponding actions for eg; handle from Create Instance Or Workbook Name data item Or sheet name or incorrect path. Anything else like if the parameters are not passed correctly eg; handle is created for one workbook but passed for another also creates the issue.
 

Waszeq

New Member
This is Sheet 4. Refer formula in C column
View attachment 1752

Sheet5 without any data
View attachment 1753

Parameters to the new custom action
View attachment 1754

Sheet5 after running the new action pasted with only values and without the formula
View attachment 1755

Below is the code in the new action

Code:
Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet, source, destination, cells, cell As Object

Try

sw = GetWorkbook(Handle, Source_Workbook)
dw = GetWorkbook(Handle, Destination_Workbook)

ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)
ds = GetWorksheet(Handle, Destination_Workbook, Destination_Worksheet)

sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet
cell = excel.ActiveCell

If Source_Range="" Then
    cells = sheet.Cells
    Destination_Range = "A1"
Else
    cells = sheet.Range(Source_Range)
End If

cells.Select()
source = excel.Selection
source.Copy()
cell.Select()

dw.Activate()
ds.Activate()
sheet = excel.ActiveSheet
cell = excel.ActiveCell
destination = sheet.Range(Destination_Range)
destination.Select()
'sheet.Paste()
destination.PasteSpecial(Paste:=-4163)  '-4163 for xlPasteValues
cell.Select()

My.Computer.Clipboard.Clear()

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    sw = Nothing
    ss = Nothing
    dw = Nothing
    ds = Nothing
    excel = Nothing
    sheet = Nothing
    source = Nothing
    destination = Nothing
    cells = Nothing
    cell = Nothing
End Try


Hi VJR,

I have different issue:
View attachment issue.png
Do you have any idea how to fix this?
 
Hi Priya/All,

Can you suggest solution because I have same requirement too?

I want to copy data of last column that has value which means, first go to last empty column and then "-1"
 

Attachments

  • LastEmptyCell.JPG
    53 KB · Views: 15

charan369

New Member
Hello VGR I get the next error ": Failed to copy worksheet: The given key was not present in the dictionary."


hi VJR,

even i am facing the same issue. "Failed to copy worksheet: The given key was not present in the dictionary"

when i am using same parameters and trying for default action it is working fine .
but when i am trying to use my customized code (i.e. code with your suggested changes ) it is trowing error
"Failed to copy worksheet: The given key was not present in the dictionary" . please suggest thanks in advace
 

charan369

New Member
The dictionary key error generally appears when the parameters either input or output or both are not correctly generated from its corresponding actions for eg; handle from Create Instance Or Workbook Name data item Or sheet name or incorrect path. Anything else like if the parameters are not passed correctly eg; handle is created for one workbook but passed for another also creates the issue.



hi VJR,

even i am facing the same issue. "Failed to copy worksheet: The given key was not present in the dictionary"

when i am using same parameters and trying for default action it is working fine .
but when i am trying to use my customized code (i.e. code with your suggested changes ) it is trowing error
"Failed to copy worksheet: The given key was not present in the dictionary" . please suggest thanks in advace
 

Dolly

New Member
hi VJR

I tried with your code but I am getting exception "The given key was not present in the dictionary."
Can you please guide if you have idea regarding this.
 

charan369

New Member
hi VJR

I tried with your code but I am getting exception "The given key was not present in the dictionary."
Can you please guide if you have idea regarding this.
hi Dolly ,

have used the same MS Exel VBO and created a new action in that

or You have customized in a new object

if you are creating a new action in default VBO it should work or else you are not passing parameters correctly (syntax error)

if u have customized the logic in new object make sure that you need to use attach action of your customized code and then u need use your copy & paste worksheet range (customized) action
 
Top