for each loop

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » For each loop

For each loop

resolvedResolved · High Priority · Version 2016

For each loop

Can someone tell me why 'j' in my code below returns as "empty"?

Public Sub CreateChart()

Dim chartDataSheets() As Long
Dim numberCells As Integer
Dim arraySize As Integer
Dim i As Integer
Dim j As Variant
Dim chartData As Range
Dim Inp As String


With Application

.ScreenUpdating = False

Let Inp = ThisWorkbook.Sheets("CreateChart").Cells(3, 2).Value

Workbooks.Open (Inp)

numberCells = WorksheetFunction.CountA(ThisWorkbook.Worksheets("CreateChart").Columns(4)) + 1

arraySize = (numberCells - 2)

ReDim chartDataSheets(arraySize)

For i = 3 To numberCells

chartDataSheets((i - 2)) = ThisWorkbook.Worksheets("CreateChart").Cells(i, 4).Value

Next i

'MsgBox chartDataSheets(1)
'MsgBox chartDataSheets(2)

For Each j In chartDataSheets

ActiveWorkbook.Worksheets(j).Activate

chartData = ActiveWorkbook.Worksheets(j).UsedRange.Select

Next j

End With

End Sub

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Hiding and unhiding rows using the keyboard

CTRL + 9 hides your columns and CTRL + SHIFT + ( unhides them although you would need to highlight the row letters either side as per normal

View all Excel hints and tips


Server loaded in 0.08 secs.