Input value into sheet, vba

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,550
The following macro works only about 80% of the time. I'm pretty sure the problem lies with the 3rd party software xlwings. I'm using xlwings to call Excel. The Macro is so simple that I seriously doubt the problem lies with Excel. Then again, I don't see why there should be a problem with xlwings since all it does is just input the values into the subroutine. Perhaps there is a more reliable VBA way of doing things.

Sub input_into_time(rw As Integer, col As Integer, val As String):
Dim time2 As Workbook, arr1 As Variant
Dim tmsheet As Worksheet
Set time2 = Workbooks("time2.xlsx")
Set tmsheet = Worksheets("time")
tmsheet.Cells(rw, col) = val
End Sub

I get a subscript out of range error on line

Set tmsheet = Worksheets("time")

And clearly there is a sheet named time in the workbook 'time2.xlsx'

I've also tried:

Sub input_into_time3(rw As Long, col As Long, val As String):
Application.ScreenUpdating = False
Workbooks("time2.xlsx").Activate
Sheets("time").Activate
Cells(rw, col) = val
Application.ScreenUpdating = True
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,550
https://ibb.co/cYcuLK https://ibb.co/bGDZLKhttps://ibb.co/cYcuLKhttps://ibb.co/bGDZLK

Here you can also see in these photos that in the local window there is clearly a sheet named 'time'. I was not able to get the photo of the workbook named time2 because the VBA editor breaks down after a few seconds. But still the workbook is clearly there.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,005
Messages
5,526,233
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top