Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA sub doesn't select the range of a specific Worksheet

I just want to get the range from A1:A80 from a sheet called "Children" but I debug it, it gets nothing. Here’s my code below:

   Dim wks2 As Worksheet
   Dim children As Range
   Worksheets("Children").Activate
   Set wks2 = Worksheets("Children")
   Set children = wks2.Range("A1:A80")
   ResetChild (children) //The sub that I want to call. Explanation bellow.

In the function ResetChild I want to delete all the sheets in my Workbook, that have names equal to the first column of the sheet Children. (A1:A80) So here’s my sub below:

Sub ResetChild(children As Range)
Call DisableCalculations
Dim cell As Range
    
For Each cell In children
    Set childrenSheet = Worksheets(cell.Value)
        If (DoesSheetExist(childrenSheet)) Then
            Application.DisplayAlerts = False
            Sheets(childrenSheet).Delete
            Application.DisplayAlerts = True
        End If
End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your code should work.
How do you know that it returns nothhing?
put the row in the end of your code

   Debug.Print children.Count

if it returns >0 then all ok and children is the range object with data

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading