Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default FillDown from unknown column

I'm adding a formula to a column that I don't know in advance, and I need
to fill the formula down the same number of rows as there are in column A.

If I knew the column, I would do something like:

LastRow = Cells.SpecialCells(xlLastCell).Row
Range("F1:F" Trim(Str(LastRow))).FillDown

How can I do this?

Thanks,
Woody
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default FillDown from unknown column

Assuming the unknown columns are contiguous,

Sub UnknownFillDown()
Dim ColCount
Dim rng1

Sheet1.Range("A1").Activate
Selection.CurrentRegion.Select
ColCount = Selection.Columns.Count
ColCount = ColCount + 1
Sheet1.Cells(1, ColCount).Activate
Sheet1.Cells(1, ColCount).Formula = "=TRIM(A1)"
rng1 = ActiveCell.Address
Range(rng1, Range("A1").End(xlDown)).Offset(0, ColCount - 1).FillDown
End Sub

Adjust sheet name, ranges, and formula as needed,
Mike

"Woody" wrote in message
.119...
I'm adding a formula to a column that I don't know in advance, and I need
to fill the formula down the same number of rows as there are in column A.

If I knew the column, I would do something like:

LastRow = Cells.SpecialCells(xlLastCell).Row
Range("F1:F" Trim(Str(LastRow))).FillDown

How can I do this?

Thanks,
Woody



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default FillDown from unknown column

Thanks Mike. That was a great help. Here's the code I wound up with.
For some reason it didn't work if the sheet wasn't active.

Sub AddCAPPivotFields()

' Add Cap Pivot Fields
' Assumes first criteria is cost account

Dim oDatasheet As Worksheet
Dim LastRow As Long
Dim LastCol As Long

On Error Resume Next

Set oDatasheet = ActiveWorkbook.Worksheets("Data")
If oDatasheet Is Nothing Then
MsgBox "Active workbook doesn't appear to be a Cobra spreadsheet
report.", vbCritical
Exit Sub
End If

With oDatasheet
.Activate 'don't understand why this necessary
LastCol = .Cells.SpecialCells(xlLastCell).Column
.Cells(1, LastCol + 1).Formula = "=LEFT(A1,6)"
.Cells(1, LastCol + 2).Formula = "=LEFT(A1,FIND("" "",A1)-1)"
.Cells(1, LastCol + 3).Formula = "=MID(A1,FIND("" "",A1)+1,FIND(""
"",A1,FIND("" "",A1,FIND("" "",A1,FIND("" "",A1)+1)+1)+1)-FIND("" "",A1)-
1)"
.Cells(1, LastCol + 4).Formula = "=RIGHT(A1,LEN(A1)-FIND(""
"",A1,FIND("" "",A1,FIND("" "",A1,FIND("" "",A1)+1)+1)+1))"
rng1 = .Cells(1, LastCol + 1).Address
.Range(rng1, Range("A1").End(xlDown)).Offset(0, LastCol).FillDown
End With
End Sub


"Mike Fogleman" wrote in
:

Assuming the unknown columns are contiguous,

Sub UnknownFillDown()
Dim ColCount
Dim rng1

Sheet1.Range("A1").Activate
Selection.CurrentRegion.Select
ColCount = Selection.Columns.Count
ColCount = ColCount + 1
Sheet1.Cells(1, ColCount).Activate
Sheet1.Cells(1, ColCount).Formula = "=TRIM(A1)"
rng1 = ActiveCell.Address
Range(rng1, Range("A1").End(xlDown)).Offset(0, ColCount - 1).FillDown
End Sub

Adjust sheet name, ranges, and formula as needed,
Mike

"Woody" wrote in message
.119...
I'm adding a formula to a column that I don't know in advance, and I
need to fill the formula down the same number of rows as there are in
column A.

If I knew the column, I would do something like:

LastRow = Cells.SpecialCells(xlLastCell).Row
Range("F1:F" Trim(Str(LastRow))).FillDown

How can I do this?

Thanks,
Woody




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
SUM IF - What if column number is unknown Milind Keer[_2_] Excel Discussion (Misc queries) 3 October 23rd 08 05:22 PM
Unknown # cells need to be in one column - Macro [email protected] Excel Discussion (Misc queries) 2 May 28th 06 08:33 PM
A function that looks for a value on a sheet on unknown column or row Paul134 Excel Worksheet Functions 2 February 28th 06 09:07 PM
FillDown Mike Fogleman Excel Programming 2 November 18th 03 10:46 PM
Need to Find End Value of a Column with Unknown End Range Tricia[_3_] Excel Programming 2 August 24th 03 07:20 PM


All times are GMT +1. The time now is 09:27 AM.

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

About Us

"It's about Microsoft Excel"