ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   STUPID range object error (https://www.excelbanter.com/excel-programming/388947-stupid-range-object-error.html)

Susan

STUPID range object error
 
Public Sub Copy_2_Cohort()

Set wsCohort = wb.Worksheets("CohortList")
iCohortRow = wsCohort.Cells(5000, 2).End(xlUp).Offset(1, 0).Row
Set rCohortStudent = wsCohort.Range("b" & iCohortRow)
Set rClass = wsCohort.Range("a" & iCohortRow)

rCohortStudent = sStudent
rClass = sClass

End Sub

============================
all variables are dimmed as indicated in a global variables module.

there's no reason (that i can see) why this doesn't work! half of the
time it runs through, but either rCohortStudent or rClass is left
blank (when the intellisense & various test messageboxes give the
correct range.address & text). the other half of the time it breaks
on either rCohortStudent OR rClass being unidentified objects. when
it was rClass that was left blank, i tried

Set rClass = rCohortStudent.Offset(0,-1)

that worked once, but then started breaking an error - saying object
wasn't set (when intellisense showed that rCohortStudent WAS set,
properly!).

i tried setting these ranges as variants (vClass), but that didn't
work.

i've compared these statements to working statements in other subs,
and i don't see what the problem is!

this is part of a huge, ungainly macro, so i thought perhaps since it
broke out of code an application.enableevents (or something) hadn't
been reset to true, so i ran another sub:

Sub reset_everything()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.DataEntryMode = True
End Sub

didn't help.

at this point i am considering reworking the structure of the macros &
modules so they flow better (more in order rather than go-over-here,
go-over-there).

any ideas?
thanks a lot!
susan


Gary Keramidas

STUPID range object error
 
where is wb dimmed?

--


Gary


"Susan" wrote in message
oups.com...
Public Sub Copy_2_Cohort()

Set wsCohort = wb.Worksheets("CohortList")
iCohortRow = wsCohort.Cells(5000, 2).End(xlUp).Offset(1, 0).Row
Set rCohortStudent = wsCohort.Range("b" & iCohortRow)
Set rClass = wsCohort.Range("a" & iCohortRow)

rCohortStudent = sStudent
rClass = sClass

End Sub

============================
all variables are dimmed as indicated in a global variables module.

there's no reason (that i can see) why this doesn't work! half of the
time it runs through, but either rCohortStudent or rClass is left
blank (when the intellisense & various test messageboxes give the
correct range.address & text). the other half of the time it breaks
on either rCohortStudent OR rClass being unidentified objects. when
it was rClass that was left blank, i tried

Set rClass = rCohortStudent.Offset(0,-1)

that worked once, but then started breaking an error - saying object
wasn't set (when intellisense showed that rCohortStudent WAS set,
properly!).

i tried setting these ranges as variants (vClass), but that didn't
work.

i've compared these statements to working statements in other subs,
and i don't see what the problem is!

this is part of a huge, ungainly macro, so i thought perhaps since it
broke out of code an application.enableevents (or something) hadn't
been reset to true, so i ran another sub:

Sub reset_everything()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.DataEntryMode = True
End Sub

didn't help.

at this point i am considering reworking the structure of the macros &
modules so they flow better (more in order rather than go-over-here,
go-over-there).

any ideas?
thanks a lot!
susan




Susan

STUPID range object error
 
waaaaaay back in a beginning userform sub....


Public Sub cmdStart_click()

Set ws = ActiveSheet
Set wb = ActiveWorkbook


it's not released anywhere (i just double-checked).
wb always refers to this main workbook that holds the userforms & all
the code. anything else that's opened is set as newWB. i could try
setting it again, tho.... it wouldn't hurt. or i could throw in a
testing

msgbox wb.name

to check it out. although if that was wrong,

Set wsCohort = wb.Worksheets("CohortList")

wouldn't work, either.


sStudent & sClass are set somewhere else, too, but the intellisense
shows the correct text for each of the strings.

thanks for any ideas/suggestions/hari-kari methods!!!
:)
susan


On May 8, 10:19 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:
where is wb dimmed?

--

Gary

"Susan" wrote in message

oups.com...



Public Sub Copy_2_Cohort()


Set wsCohort = wb.Worksheets("CohortList")
iCohortRow = wsCohort.Cells(5000, 2).End(xlUp).Offset(1, 0).Row
Set rCohortStudent = wsCohort.Range("b" & iCohortRow)
Set rClass = wsCohort.Range("a" & iCohortRow)


rCohortStudent = sStudent
rClass = sClass


End Sub


============================
all variables are dimmed as indicated in a global variables module.


there's no reason (that i can see) why this doesn't work! half of the
time it runs through, but either rCohortStudent or rClass is left
blank (when the intellisense & various test messageboxes give the
correct range.address & text). the other half of the time it breaks
on either rCohortStudent OR rClass being unidentified objects. when
it was rClass that was left blank, i tried


Set rClass = rCohortStudent.Offset(0,-1)


that worked once, but then started breaking an error - saying object
wasn't set (when intellisense showed that rCohortStudent WAS set,
properly!).


i tried setting these ranges as variants (vClass), but that didn't
work.


i've compared these statements to working statements in other subs,
and i don't see what the problem is!


this is part of a huge, ungainly macro, so i thought perhaps since it
broke out of code an application.enableevents (or something) hadn't
been reset to true, so i ran another sub:


Sub reset_everything()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.DataEntryMode = True
End Sub


didn't help.


at this point i am considering reworking the structure of the macros &
modules so they flow better (more in order rather than go-over-here,
go-over-there).


any ideas?
thanks a lot!
susan- Hide quoted text -


- Show quoted text -




Susan

STUPID range object error
 
i haven't had a chance to test it, but working on another sub it hit
me.

rCohortStudent = sStudent
rClass = sClass

should be

rCohortStudent.Value = sStudent
rClass.Value = sClass

duh.
susan


On May 8, 10:45 am, Susan wrote:
waaaaaay back in a beginning userform sub....

Public Sub cmdStart_click()

Set ws = ActiveSheet
Set wb = ActiveWorkbook

it's not released anywhere (i just double-checked).
wb always refers to this main workbook that holds the userforms & all
the code. anything else that's opened is set as newWB. i could try
setting it again, tho.... it wouldn't hurt. or i could throw in a
testing

msgbox wb.name

to check it out. although if that was wrong,

Set wsCohort = wb.Worksheets("CohortList")

wouldn't work, either.

sStudent & sClass are set somewhere else, too, but the intellisense
shows the correct text for each of the strings.

thanks for any ideas/suggestions/hari-kari methods!!!
:)
susan

On May 8, 10:19 am, "Gary Keramidas" <GKeramidasATmsn.com wrote:



where is wb dimmed?


--


Gary


"Susan" wrote in message


roups.com...


Public Sub Copy_2_Cohort()


Set wsCohort = wb.Worksheets("CohortList")
iCohortRow = wsCohort.Cells(5000, 2).End(xlUp).Offset(1, 0).Row
Set rCohortStudent = wsCohort.Range("b" & iCohortRow)
Set rClass = wsCohort.Range("a" & iCohortRow)


rCohortStudent = sStudent
rClass = sClass


End Sub


============================
all variables are dimmed as indicated in a global variables module.


there's no reason (that i can see) why this doesn't work! half of the
time it runs through, but either rCohortStudent or rClass is left
blank (when the intellisense & various test messageboxes give the
correct range.address & text). the other half of the time it breaks
on either rCohortStudent OR rClass being unidentified objects. when
it was rClass that was left blank, i tried


Set rClass = rCohortStudent.Offset(0,-1)


that worked once, but then started breaking an error - saying object
wasn't set (when intellisense showed that rCohortStudent WAS set,
properly!).


i tried setting these ranges as variants (vClass), but that didn't
work.


i've compared these statements to working statements in other subs,
and i don't see what the problem is!


this is part of a huge, ungainly macro, so i thought perhaps since it
broke out of code an application.enableevents (or something) hadn't
been reset to true, so i ran another sub:


Sub reset_everything()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.DataEntryMode = True
End Sub


didn't help.


at this point i am considering reworking the structure of the macros &
modules so they flow better (more in order rather than go-over-here,
go-over-there).


any ideas?
thanks a lot!
susan- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -





All times are GMT +1. The time now is 05:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com