PC Review


Reply
Thread Tools Rate Thread

Selecting a range from a dynamic column heading

 
 
roadie.girl@gmail.com
Guest
Posts: n/a
 
      9th Dec 2005
Hi All -

I'm trying to select a range from a spreadsheet from a button click
(and then user will see a graph popup - he will NOT have to select
anything ..just click on the button).

Problem is that there is that the spreadsheet is dynamic with each user
(depending on what columns he wants to view).

for Person 1 spreadsheet could look like:

name date state age height
weight
jack 5/2/05 TX 54 126
205
jack 5/3/05 TX 54 126
206
jack 5/4/05 TX 54 126
201

for person 2 spreasheet could look like:

name age height weight date
state
jack 56 TX 205 5/2/05
TX
jack 56 TX 206 5/3/05
TX
jack 56 TX 201 5/4/05
TX

The column headings are always in the same row (Row 6).

If you could help me out with selecting the range, for each category
(age, weight, height, date), that would be awesome!

Here's what i have so far, that definitely doesn't work...
Dim RowStart As Integer
Dim ColCount As Integer
Dim ColStart As Integer
Dim rngA As range

ColCount = Columns.Count
ColStart = ThisWorkbook.ActiveSheet.Cells(1, 1).Column
RowStart = ThisWorkbook.ActiveSheet.Cells(1, 1).Row

For Each rngA In ActiveSheet
Offset
For i = ColStart + 1 To ColStart + ColCount - 1
'this is supposed to look at the column heading and read the
name
Select Case ThisWorksheet.CurrentRegion.Cells(6, i)
'if the name is age, then set the range to the stuff below
Case "age"
Set ageSeries =
ThisWorksheet.range(ThisWorksheet.CurrentRegion.Cells(7, i))
End Select
Next i
Next rngA

Thanks again so much for any help you have!!!
rebekah

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      9th Dec 2005
How about just continuing your select case stuff and get all the ranges:

Option Explicit
Sub testme()
Dim NameRng As Range
Dim DateRng As Range
Dim StateRng As Range
Dim AgeRng As Range
Dim HeightRng As Range
Dim WeightRng As Range

Dim FirstRow As Long
Dim LastRow As Long
Dim LastCol As Long
Dim iCol As Long

Set NameRng = Nothing
Set DateRng = Nothing
Set StateRng = Nothing
Set AgeRng = Nothing
Set HeightRng = Nothing
Set WeightRng = Nothing

With ActiveSheet
FirstRow = 1 'where headers are
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

For iCol = 1 To LastCol
Select Case LCase(.Cells(1, iCol).Value)
Case Is = "name"
Set NameRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
Case Is = "date"
Set DateRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
Case Is = "state"
Set StateRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
Case Is = "age"
Set AgeRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
Case Is = "height"
Set HeightRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
Case Is = "weight"
Set WeightRng = .Range(.Cells(1, iCol), .Cells(LastRow, iCol))
End Select
Next iCol

If NameRng Is Nothing _
Or DateRng Is Nothing _
Or StateRng Is Nothing _
Or AgeRng Is Nothing _
Or HeightRng Is Nothing _
Or WeightRng Is Nothing Then
MsgBox "Not all ranges found!"
Exit Sub
End If

'your code to create the chart.

End With

End Sub


(E-Mail Removed) wrote:
>
> Hi All -
>
> I'm trying to select a range from a spreadsheet from a button click
> (and then user will see a graph popup - he will NOT have to select
> anything ..just click on the button).
>
> Problem is that there is that the spreadsheet is dynamic with each user
> (depending on what columns he wants to view).
>
> for Person 1 spreadsheet could look like:
>
> name date state age height
> weight
> jack 5/2/05 TX 54 126
> 205
> jack 5/3/05 TX 54 126
> 206
> jack 5/4/05 TX 54 126
> 201
>
> for person 2 spreasheet could look like:
>
> name age height weight date
> state
> jack 56 TX 205 5/2/05
> TX
> jack 56 TX 206 5/3/05
> TX
> jack 56 TX 201 5/4/05
> TX
>
> The column headings are always in the same row (Row 6).
>
> If you could help me out with selecting the range, for each category
> (age, weight, height, date), that would be awesome!
>
> Here's what i have so far, that definitely doesn't work...
> Dim RowStart As Integer
> Dim ColCount As Integer
> Dim ColStart As Integer
> Dim rngA As range
>
> ColCount = Columns.Count
> ColStart = ThisWorkbook.ActiveSheet.Cells(1, 1).Column
> RowStart = ThisWorkbook.ActiveSheet.Cells(1, 1).Row
>
> For Each rngA In ActiveSheet
> Offset
> For i = ColStart + 1 To ColStart + ColCount - 1
> 'this is supposed to look at the column heading and read the
> name
> Select Case ThisWorksheet.CurrentRegion.Cells(6, i)
> 'if the name is age, then set the range to the stuff below
> Case "age"
> Set ageSeries =
> ThisWorksheet.range(ThisWorksheet.CurrentRegion.Cells(7, i))
> End Select
> Next i
> Next rngA
>
> Thanks again so much for any help you have!!!
> rebekah


--

Dave Peterson
 
Reply With Quote
 
roadie.girl@gmail.com
Guest
Posts: n/a
 
      9th Dec 2005
ah ha! thank you so much dave - i wasn't doing the Set rangeName =
Range.....etc. this works great! thanks for your help again

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create dynamic column heading in Access form? kande_ian Microsoft Access Getting Started 0 25th Nov 2010 10:32 PM
Conditional Formatting - SELECTING COLUMN HEADING IF A CELL IS COLORED manan Microsoft Excel Discussion 4 12th May 2006 03:23 PM
Dynamic Column Heading/Field Label =?Utf-8?B?RGF2aWQ=?= Microsoft Access Queries 6 17th Mar 2006 11:35 PM
Selecting data from column heading VBA Novice Microsoft Excel Programming 1 12th Apr 2005 03:23 PM
Selecting Dynamic Range Todd Huttenstine Microsoft Access VBA Modules 3 5th May 2004 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:02 AM.