Python Forum
How to Copy Single Value From One Excel Sheet to Another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Copy Single Value From One Excel Sheet to Another
#1
Hi Everyone,

I'm trying to copy one value from a worksheet to another, but I'm doing something wrong. Can someone help me understand how to do this.

I'm trying to copy a value from workbook(Weekly Data.xlsx) worksheet(DateData)Column H row 4 to workbook(Weekly-temp.xlsx) worksheet (Cutter A - Marker Report) Column C row 4.

Value in Workbook(Weekly Data.xlsx) is in a date format "MM/DD/YY".

# Import 'load_workbok' module from 'openpyxl'
from openpyxl import load_workbook

# Load existing excel file into a workbook object
wb=load_workbook('Weekly-temp.xlsx')
wb1=load_workbook('Weekly Data.xlsx')
ws=wb['Cutter A - Marker Report']
ws1=wb1['DateData']
ws.cell(row=4,column=3).value=ws1.cell(row=4,column=6)

# Saving the excel file using "wb.save" method
wb.save("C:/Users/vhubb/Documents/Python Scripts/Cutter Reports/2021/01 - January/Week 01.xlsx")
When I run this project I get this error:

runfile('C:/Users/vhubb/Documents/Python Scripts/Cutter Reports/CutterReportSetup3.py', wdir='C:/Users/vhubb/Documents/Python Scripts/Cutter Reports')
Traceback (most recent call last):

  File "C:\Users\vhubb\Documents\Python Scripts\Cutter Reports\CutterReportSetup3.py", line 22, in <module>
    ws.cell(row=4,column=3).value=ws1.cell(row=4,column=6)

  File "C:\Users\vhubb\anaconda3\lib\site-packages\openpyxl\cell\cell.py", line 216, in value
    self._bind_value(value)

  File "C:\Users\vhubb\anaconda3\lib\site-packages\openpyxl\cell\cell.py", line 199, in _bind_value
    raise ValueError("Cannot convert {0!r} to Excel".format(value))

ValueError: Cannot convert <Cell 'DateData'.F4> to Excel
Thanks,
Veronica
Reply


Messages In This Thread
How to Copy Single Value From One Excel Sheet to Another - by SunWers - Dec-28-2020, 06:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 282 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 449 Feb-07-2024, 12:24 PM
Last Post: Viento
  How to copy work sheet data one workbook to other? sayyedkamran 2 707 Nov-03-2023, 09:10 AM
Last Post: Larz60+
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,888 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 2,068 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  how to read txt file, and write into excel with multiply sheet jacklee26 14 10,047 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  is it possible to copy image from email and place into excel file? cubangt 3 1,281 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Reading Excel file and use a wildcard in file name and sheet name randolphoralph 6 7,139 Jan-13-2022, 10:20 PM
Last Post: randolphoralph
  Python script for excel sheet Nabil 4 3,293 Jun-01-2021, 05:09 AM
Last Post: Pedroski55
  Copy column from one existing excel file to another file mkujawsk 0 5,650 Apr-14-2021, 06:33 PM
Last Post: mkujawsk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020