Array Empty - Range assigned to to Array

rakeshpv

New Member
Joined
Oct 4, 2015
Messages
1
Here is the code, in here i am assigning the range("A1:AH1") to array arr1 but when i try to read the array by giving the statement debug.print the first entry in the array is itself coming as empty
The code:
Private Sub CommandButton5_Click()
Dim arr1() As Variant
Dim i As Integer
Dim j As Integer
Dim wkbnew As Workbook
Dim wks As Worksheet
Dim R As Long
Dim C As Long
Set wks = Worksheets.Add(after:=Sheets(wkb1.Sheets.Count))
wks.Name = "MySheet"
wkb1.Sheets("Heading2").Activate
i = 1
j = 1
arr1 = Range("A1:AH1")
Debug.Print Range("A1")
For R = 1 To UBound(arr1, 1) ' First array dimension is rows.
For C = 1 To UBound(arr1, 2) ' Second array dimension is columns.
i = 1
Debug.Print arr1(R, C)
Debug.Print Sheets("ODS_DATA").Cells(1, i)
Do Until IsEmpty(Sheets("ODS_DATA").Cells(1, i))
Debug.Print Sheets("ODS_DATA").Cells(1, i)
If arr1(R, C) = Sheets("ODS_DATA").Cells(1, i) Then
If Sheets("MySheet").Range("A1") = "" Then
nextcol = 1
Else
nextcol = Sheets("MySheet").Cells(1, Columns.Count).End(xlToLeft).Column + 1
End If
Sheets("ODS_DATA").Cells(1, i).EntireColumn.Copy Sheets("MySheet").Cells(1, nextcol)
Exit Do
End If
i = i + 1
Loop
Next C
Next R


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top