Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Varying Range Size in Macro

I'm trying to create a macro that does the following steps.

1. Inserts a column in front of an existing column of data.
2. Enters a constant value in each cell of the new column for every
filled cell of the existing column.

I can do this the first time. However, I don't know how to make the
macro dynamic to take into account varying lengths of the existing
column. It may be 10 rows one time and 20 rows the second time.

The data might look like this:
Column A
Row 1 $100
Row 2 $200
Row 3 $300

After the macro, the data would look like this:
Column A Column B
Row 1 1234 $100
Row 2 1234 $200
Row 3 1234 $300

The next time, there will be more or less rows in Column A.

Thank you for your help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Varying Range Size in Macro

Try something like

With ActiveCell
Columns(.Column).Insert
Cells(1, .Column - 1).Value = 1234
iLastRow = Cells(Rows.Count, .Column).End(xlUp).Row
Cells(1, .Column - 1).AutoFill Range(Cells(1, .Column - 1),
Cells(iLastRow, .Column - 1))
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Charles Allen" wrote in message
...
I'm trying to create a macro that does the following steps.

1. Inserts a column in front of an existing column of data.
2. Enters a constant value in each cell of the new column for every
filled cell of the existing column.

I can do this the first time. However, I don't know how to make the
macro dynamic to take into account varying lengths of the existing
column. It may be 10 rows one time and 20 rows the second time.

The data might look like this:
Column A
Row 1 $100
Row 2 $200
Row 3 $300

After the macro, the data would look like this:
Column A Column B
Row 1 1234 $100
Row 2 1234 $200
Row 3 1234 $300

The next time, there will be more or less rows in Column A.

Thank you for your help.



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
Formulas using the same data types but with varying size groups MAC253 Excel Discussion (Misc queries) 0 October 3rd 06 04:31 PM
Macro: how to set a print area of varying size? Dave D Excel Discussion (Misc queries) 1 September 19th 06 12:50 PM
How do I compare pie charts by varying size puzzled Charts and Charting in Excel 1 February 19th 06 04:18 PM
sumif range of varying size KM01 Excel Worksheet Functions 2 March 30th 05 10:19 AM
Setting Print Size for varying Printer use indigo Excel Programming 6 June 11th 04 05:38 PM


All times are GMT +1. The time now is 06:39 PM.

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"