98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » For each loop
For each loop
Resolved · High Priority · Version 2016
Andrew has attended:
Excel Advanced - Formulas & Functions course
Excel VBA Introduction course
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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Hiding and unhiding rows using the keyboardCTRL + 9 hides your columns and CTRL + SHIFT + ( unhides them although you would need to highlight the row letters either side as per normal |