[FONT="]Hi everyone. I've got a button that's supposed to sort a table when clicked but it's giving me a run time 1004 error. Any idea why? The .Apply line gets highlighted.
It happens wheter the sheet is protected or not.[/FONT]
[FONT="]
[/FONT]
[FONT="]
[/FONT]
It happens wheter the sheet is protected or not.[/FONT]
[FONT="]
[/FONT]
[FONT="]
[/FONT]
Code:
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Sub PulsanteRiordinaA_Click()
Application.Screenupdating=False
Activesheet.Unprotect</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim lo As Excel.ListObject</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]
[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Set lo = ActiveWorkbook.Worksheets("Dati Anagrafici").ListObjects("TabellaAnagrafe")</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">With lo</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.Sort.SortFields.Clear</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.Sort.SortFields.Add _</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Key:=Range("TabellaAnagrafe"), SortOn:=xlSortOnValues, Order:=xlAscending, _</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">DataOption:=xlSortNormal</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">With .Sort</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.Header = xlYes</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.MatchCase = False</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.Orientation = xlTopToBottom</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.SortMethod = xlPinYin</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">.Apply
Activesheet.Protect
Application.Screenupdating = True</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">End With</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">End With</code>[/FONT][/COLOR]
[COLOR=#1C1C1C][FONT="]<code class="s90z9tc-7 klSgyG" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">End Sub</code>[/FONT][/COLOR]