![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 93
|
I have a macro that finds a column called Product Type, inserts a blank column and then inserts a formula 1 row down. I would like to Autofill that formula down in my macro. Problem is, Product Type could be in different columns depending on which report I download into Excel. I have found the following code on this site but it only autofills from cell B2. Can it be modified to Autofill my formula depending on where the Product Type column is located?
Range("a2").Select fillrange = Range(Selection, Selection.End(xlDown)).Offset(0, 1).Address Set SourceRange = Worksheets("Sheet1").Range("b2") SourceRange.AutoFill Destination:=Range(fillrange) |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
This does what your macro does plus it will fill down the fromula based upon the rows of data in Column A Edit to suit. Tom
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Posts: 93
|
THANK YOU! That's exactly what I was looking for. You're the Man!!
|
|
|
|
|
|
#4 |
|
Join Date: Mar 2002
Posts: 15
|
Hi TsTom
I'm not trying to be critical, but you might find the following alternative interesting :- Sub FindColumn() Dim c%, lastRow# lastRow = [A65536].End(xlUp).Row c = [A1:IV1].Find("Product Type").Column + 1 Columns(c).Insert Range(Cells(2, c), Cells(lastRow, c)).Formula = _ "=SUM(" & Cells(2, c - 1).Address(False, False) & " + 1)" End Sub |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
No offense here...
I'm a beginner and have taken alot of pleasure from learning on this site... Tom |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|