Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Formatting cells entered by a macro

I have a macro, that selects the last row in a range of cells and inputs a
blank row just above this (as below).

I want to then format the cells I input, and am having trouble writing the
macro to select them

Can anyone help?


Dim LastRow As Long, NumberOfBlankRows
NumberOfBlankRows = 1
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Intersect(Range("A:R"), Rows(LastRow)).Resize(NumberOfBlankRows).Insert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Formatting cells entered by a macro

You didn't tell us what kind of format you wanted to apply to the cells, so
I am just assuming a custom date format... change the NumberFormat line to
suit your needs. Note that in the code below, I removed the
NumberOfBlankRows variable and the Resize event that used it... I wasn't
sure from the wording of your first thread on this subject whether you
wanted a user defined number of rows or just one to be inserted... your post
indicates you only wanted one, so the code can be simplified for that
condition.

Dim LastRow As Long, NumberOfBlankRows
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
With Intersect(Range("A:R"), Rows(LastRow))
.Insert
.Offset(-1).NumberFormat = "mmmm d, yyyy"
End With

By the way, note that I do not select the cells between columns A and R in
order to format them... there is no need to select the cells in order to
perform this operation on them. Also note that I used a With..End With block
so the Intersect operation did not have to be specified multiple times.

--
Rick (MVP - Excel)


"Kirsty" wrote in message
...
I have a macro, that selects the last row in a range of cells and inputs a
blank row just above this (as below).

I want to then format the cells I input, and am having trouble writing the
macro to select them

Can anyone help?


Dim LastRow As Long, NumberOfBlankRows
NumberOfBlankRows = 1
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Intersect(Range("A:R"), Rows(LastRow)).Resize(NumberOfBlankRows).Insert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Formatting cells entered by a macro

I am trying to format the borders, so I have a black border around each
square, is that possible?

"Rick Rothstein" wrote:

You didn't tell us what kind of format you wanted to apply to the cells, so
I am just assuming a custom date format... change the NumberFormat line to
suit your needs. Note that in the code below, I removed the
NumberOfBlankRows variable and the Resize event that used it... I wasn't
sure from the wording of your first thread on this subject whether you
wanted a user defined number of rows or just one to be inserted... your post
indicates you only wanted one, so the code can be simplified for that
condition.

Dim LastRow As Long, NumberOfBlankRows
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
With Intersect(Range("A:R"), Rows(LastRow))
.Insert
.Offset(-1).NumberFormat = "mmmm d, yyyy"
End With

By the way, note that I do not select the cells between columns A and R in
order to format them... there is no need to select the cells in order to
perform this operation on them. Also note that I used a With..End With block
so the Intersect operation did not have to be specified multiple times.

--
Rick (MVP - Excel)


"Kirsty" wrote in message
...
I have a macro, that selects the last row in a range of cells and inputs a
blank row just above this (as below).

I want to then format the cells I input, and am having trouble writing the
macro to select them

Can anyone help?


Dim LastRow As Long, NumberOfBlankRows
NumberOfBlankRows = 1
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Intersect(Range("A:R"), Rows(LastRow)).Resize(NumberOfBlankRows).Insert


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Formatting cells entered by a macro

This code should do what you want...

Dim LastRow As Long, NumberOfBlankRows
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
With Intersect(Range("A:R"), Rows(LastRow))
.Insert
With .Offset(-1)
.BorderAround Weight:=xlThick
.Borders(xlInsideVertical).Weight = xlThick
End With
End With

In addition to the weight of the line, you can also control the color and
line style if desired.

--
Rick (MVP - Excel)


"Kirsty" wrote in message
...
I am trying to format the borders, so I have a black border around each
square, is that possible?

"Rick Rothstein" wrote:

You didn't tell us what kind of format you wanted to apply to the cells,
so
I am just assuming a custom date format... change the NumberFormat line
to
suit your needs. Note that in the code below, I removed the
NumberOfBlankRows variable and the Resize event that used it... I wasn't
sure from the wording of your first thread on this subject whether you
wanted a user defined number of rows or just one to be inserted... your
post
indicates you only wanted one, so the code can be simplified for that
condition.

Dim LastRow As Long, NumberOfBlankRows
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
With Intersect(Range("A:R"), Rows(LastRow))
.Insert
.Offset(-1).NumberFormat = "mmmm d, yyyy"
End With

By the way, note that I do not select the cells between columns A and R
in
order to format them... there is no need to select the cells in order to
perform this operation on them. Also note that I used a With..End With
block
so the Intersect operation did not have to be specified multiple times.

--
Rick (MVP - Excel)


"Kirsty" wrote in message
...
I have a macro, that selects the last row in a range of cells and inputs
a
blank row just above this (as below).

I want to then format the cells I input, and am having trouble writing
the
macro to select them

Can anyone help?


Dim LastRow As Long, NumberOfBlankRows
NumberOfBlankRows = 1
LastRow = Range("A3:R1000").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Intersect(Range("A:R"), Rows(LastRow)).Resize(NumberOfBlankRows).Insert


.


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
Conditional Formatting according to the date the data is entered hadeeter Excel Discussion (Misc queries) 1 May 6th 10 08:16 PM
Formatting Text in cells that already have text entered Jennifer V. Excel Worksheet Functions 4 January 13th 09 09:27 PM
Using a Macro in Excel 2004 to move entered data from one sheet toanother and space between rows when next data is entered? [email protected] Excel Programming 1 June 4th 08 05:08 PM
Formatting a cell to show something different the entered value TTAmo Excel Discussion (Misc queries) 6 April 24th 08 03:58 PM
Running a macro if any data is entered in a range of cells Jonathan Excel Worksheet Functions 3 November 16th 05 08:38 PM


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