Link to home
Start Free TrialLog in
Avatar of shilpi2
shilpi2

asked on

Picking column headings

Hi Experts,

I have an excel sheet and I want to pick up headings from row 4,row 5 column G onwards in an array in visual basic.
Also the array I create has to be dynamic as I do not know beforehand how many columns to go beyond G. I have to stop before the point it becomes blank
How do I do it?

Thanks

Shilpi
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you provide more detail. Do you want the values in G4, G5, H4, H5 etc (until you find a blank) in an array? Or G4, H4 etc in one array and G5, H5 in another? Or G4, H4, G4, G5...?
Avatar of shilpi2
shilpi2

ASKER

The first one. G4,G5,H4,HG etc in one array until i come across a blank
ASKER CERTIFIED SOLUTION
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shilpi2

ASKER

Hi,

I have to write this code in another worksheet. How do I modify this code so that it loops another worksheet.

Thanks
Adjust sheet name as required:
Sub x()

Dim v(), c As Long, i As Long

c = 7

Do Until IsEmpty(Sheet("Name").Cells(4, c))
    i = i + 2
    ReDim Preserve v(1 To i)
    v(i - 1) = Sheet("Name").Cells(4, c)
    v(i) = Sheet("Name").Cells(5, c)
    c = c + 1
Loop

End Sub

Open in new window