LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default variable - insert blank row/select range

Thank you...thank you...Bgeier and somethinglikeant. I only wish I knew VBA
to accomplish so many of these type of tasks. While the "record macro" gets
one started it does have its draw backs for using the macro again when lists
are involved.

Jan

"bgeier" wrote:


Try this.
It is a combination of your code (looks like a recorded macro) and
somethinglikeant's code.

I have tried to explain the steps, but if you need any clarification,
do not hesitate to post.

Option Explicit

Sub Order()
Dim intCounter As Integer
Dim dblActiveRow As Double

Cells(2, 21).Select 'does the same as your Range("U2").Select code
'Start the loop since you are looking for 1 or 2 or 3, you only
need to count from 1 to 3
For intCounter = 1 To 3
'This is the same code as your find, I just removed the
unnecessary prompts
Cells.Find(intCounter, ActiveCell, xlFormulas, xlWhole,
xlByColumns, xlNext, False, False).EntireRow.Select
'Insert the row
Selection.EntireRow.Insert
'You only want to add the color to columns A to R. so you need
to store the row number to define the range
dblActiveRow = ActiveCell.Row
'Select column "A" through "R" on the selected row (A = 1, R =
18)
Range(Cells(dblActiveRow, 1), Cells(dblActiveRow, 18)).Select
'Insert Page Break
ActiveSheet.HPageBreaks.Add Befo=ActiveCell
'Format the selection
With Selection
.Interior.ColorIndex = 41
.Font.ColorIndex = 2
.Font.Name = "Arial"
.Font.Bold = True
.Font.Italic = True
.Font.Size = 14
End With
'This decides which "header" goes with each search
Select Case intCounter
Case 1: Cells(dblActiveRow, 2) = "Mike"
Case 2: Cells(dblActiveRow, 2) = "MAM"
Case 3: Cells(dblActiveRow, 2) = "To Printer"
End Select
Next intCounter
'Make the columns only as wide as needed
Columns.AutoFit
'Make the rows only as tall as needed
Rows.AutoFit
End Sub


--
bgeier
------------------------------------------------------------------------
bgeier's Profile: http://www.excelforum.com/member.php...o&userid=12822
View this thread: http://www.excelforum.com/showthread...hreadid=541689


 
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
Select a variable range Bluecat Excel Worksheet Functions 7 January 13th 09 01:24 AM
how do I insert a variable amount of blank spaces in a formula? Lucy4484 Excel Worksheet Functions 1 January 14th 07 10:36 PM
Use a Variable to select a range Connie Excel Discussion (Misc queries) 3 October 19th 06 05:48 PM
select a variable range evil baby[_15_] Excel Programming 4 March 8th 06 08:38 PM
Select a Range Through a Variable GoFigure[_9_] Excel Programming 3 December 6th 05 01:02 PM


All times are GMT +1. The time now is 03:29 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"