excel - Why do some methods/properties require a certain sheet to be active while others do not? -


why of of methods , properties use in vba require sheet active while others not?

the following example works no matter if wks active or not:

wks.range("a1").value = 1 

the following example works if wks active otherwise error thrown:

wks.range("a1:a70").insert 

edit: thought had insert function judging gary's students answer did not. exact code triggered me ask question is:

'cut range source row dim lsourcerow long dim lsourcestartcolumn long dim lsourceendcolumn long lsourcerow = t.row lsourcestartcolumn = losource.range.column lsourceendcolumn = losource.range.column + losource.listcolumns.count - 1 wkssource.range(wkssource.cells(lsourcerow, lsourcestartcolumn), wkssource.cells(lsourcerow, lsourceendcolumn)).cut  'select target worksheet insert method wkstarget.activate  'insert range target row dim ltargetrow long dim ltargetstartcolumn long dim ltargetendcolumn long ltargetrow = lotarget.databodyrange.row + lotarget.listrows.count ltargetstartcolumn = lotarget.range.column ltargetendcolumn = lotarget.range.column + lotarget.listcolumns.count - 1 wkstarget.range(cells(ltargetrow, ltargetstartcolumn), cells(ltargetrow, ltargetendcolumn)).insert 

and understand why. must because haven't prefaced cells worksheet object. should be:

wkstarget.range(wkstarget.cells(ltargetrow, ltargetstartcolumn), wkstarget.cells(ltargetrow, ltargetendcolumn)).insert 

conclution this:

the more experienced guys reading welcome close thread since problem had thought.

otherwise, going original question, curious: vba commands require worksheet active or never have use worksheet.select in code? i'm wondering because know have encountered "problem" before. maybe made mistake in code.

you have other un-related bug. following works without error in absence of protection:

sub dural()     sheets("sheet2").select     sheets("sheet1").range("a1").insert end sub 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -