I coded some vba procedures in different modules. Then, there is a UserForm and in the UserForm there are Subs like this within I call the subs in the modules:
Sub uf2_imp_new_Click()
Call a_xxx_delete '[Sub in Module A]
Call a_xxx_import '[Sub in Module A]
Call b_TransXXX '[Sub in Module B]
Call c_plist_reset_all '[Sub in Module C]
Call c_xxx_listfrom_transANB '[Sub in Module C]
End Sub
When Executing I get a runtime error 1004 "Method Range failed for Object Worksheet" in Module C Sub c_xxx_listfrom_transANB:
Option Explicit
Sub c_xxx_listfrom_transANB()
Dim wb As Workbook
Dim ws_trans_anb As Worksheet
Dim ws_plist As Worksheet
Dim zeile_trans As Integer
Dim zeile_plist As Integer
Set wb = ThisWorkbook
Set ws_trans_anb = wb.Worksheets("Trans_XXX")
Set ws_plist = wb.Worksheets("PROJEKTLISTE")
letztezeile = ws_trans_anb.Cells(Rows.Count, 1).End(xlUp).Row
For zeile_trans = 2 To letztezeile
[...]
ws_plist.Range(Cells(zeile_plist, 2), Cells(zeile_plist, 16)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Next
EndSub
The highlighted Row when the error occurs is
ws_plist.Range(Cells(zeile_plist, 2), Cells(zeile_plist, 16)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Does anyone has an idea how to fix that? I coded the module c days ago and there never was an error. But now when Calling the sub via User form it doesnt work anymore.. And its strange: the I execute the Sub in Module C by klicking "Play" in VBA, the error occurs. But when I execute the Sub in Module C Step by Step there is no error. Thats too much for me.. :) Can anyone help?
ws_plist.Range(Cells
does not meanws_plist.Range(ws_plist.Cells
so you need to fully qualify all of your cell references like that too – braXws_plist.Range(Cells
actually meansws_plist.Range(ActiveSheet.Cells
- so whenwsp_plist
is the same asActiveSheet
it will work, and when it's not, it won't. – braX