Input value into sheet, vba

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
bGDZLK
https://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.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top