Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Macro to sequence ("$A:$A") to ("$IV:$IV")

On Oct 28, 3:18 pm, "Bill Renaud"
wrote:
I revised the routine as follows. I added a function to determine the
actual data area in each column (both Data and Bin values). The logic
inside the For loop now only creates a Histogram if the number of cells on
the data worksheet is greater than 1 (column must have data besides the
column label). I used "Bins" for the name of the worksheet that has the Bin
values (you can change it back to "Sheet4", if you like).

I also name each Histogram worksheet as "Hist Column #", where "#" is the
column number where the data originated from.

'----------------------------------------------------------------------
Public Sub MakeHistograms()
Dim wsData As Worksheet 'Worksheet that contains the data.
Dim wsBins As Worksheet 'Worksheet with bin values.
Dim lngColumnsOfData As Long 'Number of columns of non-blank data.
Dim ilngColumn As Long 'Index of columns on Data and Bin sheets.
Dim rngData As Range
Dim rngBin As Range

Application.ScreenUpdating = False

Set wsData = ActiveSheet
Set wsBins = ActiveWorkbook.Worksheets("Bins")

lngColumnsOfData = wsData.UsedRange.Columns.Count

For ilngColumn = 1 To lngColumnsOfData
Set rngData = DataColumn(wsData.Cells(1, ilngColumn))

'Create Histogram only if column actually contains data.
'Assume row 1 is the header (column label).
If rngData.Cells.Count 1 _
Then
Set rngBin = DataColumn(wsBins.Cells(1, ilngColumn))

Application.Run "ATPVBAEN.XLA!Histogram", _
rngData, _
"", _
rngBin, _
False, False, True, True

'Newly-created Histogram worksheet is now active.
With ActiveSheet
.Name = "Hist Column " & ilngColumn
.Range("$A$1").Select
End With
End If
Next ilngColumn
End Sub

'----------------------------------------------------------------------
'DataColumn returns a range that is the extension of CellRow1
'down to the last non-blank cell in the same column.

Private Function DataColumn(CellRow1 As Range) As Range
Dim ws As Worksheet
Dim rngColumn As Range
Dim rngLastCell As Range

Set ws = CellRow1.Parent
Set rngColumn = CellRow1.EntireColumn
Set rngLastCell = rngColumn.Find _
(What:="*", _
After:=CellRow1, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
If rngLastCell Is Nothing _
Then
'Column is totally blank; it contains no data!
Set DataColumn = CellRow1
Else
Set DataColumn = ws.Range(CellRow1, rngLastCell)
End If
End Function

--
Regards,
Bill Renaud


Bill, thanks a lot for this code too. I will give this a shot

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... Maria J-son[_2_] Excel Programming 2 March 5th 06 12:20 PM


All times are GMT +1. The time now is 04:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"