excel - VBA Run-time error '1004': Selection.Interior.Pattern -



excel - VBA Run-time error '1004': Selection.Interior.Pattern -

i have next code should alter decoration of named range based on there beingness value within it. if empty turns reddish , if not should clear decoration. have looked @ other questions similar errors , cannot seem prepare issue. have next code:

each section in mandatoryfields msgbox (thisworkbook.worksheets("worksheet").range(section).value) if trim(thisworkbook.worksheets("worksheet").range(section).value) = "" thisworkbook.worksheets("worksheet").range(section).select selection.interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 255 .tintandshade = 0 .patterntintandshade = 0 end else thisworkbook.worksheets("worksheet").range(section).select selection.interior .pattern = xlnone .tintandshade = 0 .patterntintandshade = 0 end end if next section

i have stepped through code , runtime error beingness triggered @ the

.pattern = xlnone

or

.pattern = xlsolid

lines. suggestions?

i have tried

worksheets("worksheet").activate range(section).select selection.interior .pattern = xlnone .tintandshade = 0 .patterntintandshade = 0 end

i have next code triggered on button click.

dim wb workbook set wb = application.workbooks("c new hire") wb.worksheets("worksheet").range("namerange").value = "r"

a runtime error occur on sec time click button on line

wb.worksheets("worksheet").range("namerange").value = "r"

the coloring part of code right works:

sub luxation() range("a1:a2").clear range("a1").select selection.interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 255 .tintandshade = 0 .patterntintandshade = 0 end range("a2").select selection.interior .pattern = xlnone .tintandshade = 0 .patterntintandshade = 0 end end sub

however:

before selecting range, must activate "containing" worksheet.

otherwise, follow david's advice.

edit#1:

based on updated code, after:

range(section).select

insert:

msgbox selection.address(0,0)

this shed lite on problem happening.

excel vba excel-vba

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -