0

I have very little knowledge of VBA

I have a macro that I would like to work across multiple worksheets in the same workbook. All worksheets are identical

The code works in the original worksheet but I get an error message in the others. Please help

I appreciate the feedback. Can you please explain how would I set an explicit worksheet qualifier?

Is it possible to attach the file in '.xlsb'?

this is the code

If ActiveSheet.Range("A3").Value = 1 Then
    Exit Sub
Else:
    Range("A3").Value = Range("A3").Value - 1
    LeaveTracker.Columns("B:NI").Hidden = True
    LeaveTracker.Range(Columns(Range("A3").Value * 31 - 29), Columns(Range("A3").Value * 31 + 1)).Hidden = False
End If
End Sub

Sub NextMonth()
If ActiveSheet.Range("A3").Value = 12 Then
    Exit Sub
Else:
    Range("A3").Value = Range("A3").Value + 1
    LeaveTracker.Columns("B:NI").Hidden = True
    LeaveTracker.Range(Columns(Range("A3").Value * 31 - 29), Columns(Range("A3").Value * 31 + 1)).Hidden = False
End If
End Sub

help_andy
  • 1
  • 2
  • 4
    Every call to Columns or Range should have an explicit worksheet qualifier – Tim Williams Jul 05 '21 at 19:19
  • 1
    See this post: [How to avoid using Select in Excel VBA](https://stackoverflow.com/q/10714251/1422451) – Parfait Jul 05 '21 at 21:11
  • Andy, my VBA is a little rusted, but I would guess that you either have to iterate from a collection of worksheets, avoiding `ActiveSheet` or, while iterating, changing the active sheet. I would gladly help you, but it's too much work to write a POC to your code... could you share with us the '.xlsb', of course, writing out any sensitive information? – Marcus Vinicius Pompeu Jul 06 '21 at 05:12

0 Answers0