PC Review


Reply
Thread Tools Rate Thread

Adding 4 rows after each total criteria in the column A with formatting and added text using macro.

 
 
simplymidori76@gmail.com
Guest
Posts: n/a
 
      20th Mar 2007
Hello,

I have been working on this project for ages now and I have little
more fine tuning to do before it's offically automated friendly.

AIM is

To add 4 rows after "total" with color and text.
Insert row a with text as "Avails" under "Total" and entire row
background color as Blue
Insert row b with text as "Left" under "Avails" and entire row
background color as Yellow
Insert row c & d are just empty rows.

I would like to do this after every "total" criteria in column A.


ie

A B C D
"" 1
"" 0
"" 2
"" 2
Total 5
row a "Avails"
row b "Left"
row c
row d
""
""
""
""
""
""
Total
row a "Avails"
row b "Left"
row c
row d

 
Reply With Quote
 
 
 
 
Incidental
Guest
Posts: n/a
 
      20th Mar 2007
Hi

You could try something like this

Option Explicit
Dim MyCell, MyRng As Range
Dim i As Integer

Private Sub CommandButton1_Click()
Set MyRng = [a1:a100] 'set your range
For Each MyCell In MyRng
If MyCell.Value = "total" Then
MyCell.Offset(1, 0).Select
Do While i < 4
ActiveCell.EntireRow.Insert
i = i + 1
Loop
ActiveCell.Value = "Avails"
ActiveCell.EntireRow.Interior.ColorIndex = 5
ActiveCell.Offset(1, 0).Value = "Left"
ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6
End If
Next MyCell
End Sub

hope it is of some help to you

S

 
Reply With Quote
 
simplymidori76@gmail.com
Guest
Posts: n/a
 
      20th Mar 2007
Hello,

I can see the logic in this and I have attempted a few times this
morning to embed the code in a commandbutton - However it's not doing
anything for the moment.
Does this have to be a commandbutton? Can this be a customized macro
button that I can assign it. I populate this several times a week and
might be harder to constantly add a command button.



On Mar 20, 6:33 am, "Incidental" <inciden...@hotmail.co.uk> wrote:
> Hi
>
> You could try something like this
>
> Option Explicit
> Dim MyCell, MyRng As Range
> Dim i As Integer
>
> Private Sub CommandButton1_Click()
> Set MyRng = [a1:a100] 'set your range
> For Each MyCell In MyRng
> If MyCell.Value = "total" Then
> MyCell.Offset(1, 0).Select
> Do While i < 4
> ActiveCell.EntireRow.Insert
> i = i + 1
> Loop
> ActiveCell.Value = "Avails"
> ActiveCell.EntireRow.Interior.ColorIndex = 5
> ActiveCell.Offset(1, 0).Value = "Left"
> ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6
> End If
> Next MyCell
> End Sub
>
> hope it is of some help to you
>
> S



 
Reply With Quote
 
simplymidori76@gmail.com
Guest
Posts: n/a
 
      20th Mar 2007
I think it doesn't work because it is specifically looking for "total"
- the total row will have some text.

ie 04/02/07 - a b c - Total


 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      20th Mar 2007
Hi

I'm not sure exactly what you are wanting to do, from the original
description it sounds like you have a cell that appears every so often
in the column A with the value of "total"??? if this is the case you
can run the code from a button or you can assign a keyboard shortcut
to it.

you can do the latter by opening the visual basic editor or press Alt
and F11 then add a new module then paste the given code into the
module just change the line

Private Sub CommandButton1_Click()

to something like

Sub RunMyCode()

then in excel from the tools menu select the macro option, from the
Form that pops up high light your macro RunMyCode then select the
options button and add a shortcut key.

then you will be able to run the code from this shortcut.

if you don't have the cell value of "total" to mark where you are
wanting the changes to be made you will have to search for something
that will indicate which cells to run the code from, i.e. if the total
is always have 5 cells between you could use that to activate your
code.

also if you are doing this in different workbooks every time you may
have to do something like create a workbook with the code you want to
run then add a little bit of code to open the other workbook and then
run the code on that workbook as having to add the code every time is
very impractical.

hope this is somewhat clearer

 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      20th Mar 2007
Back again

sorry i forgot to add if you wish to run the code more than once in
the same session you should reset the integer i to 0 you can do this
by adding the line "i = 0" above end sub


S

 
Reply With Quote
 
simplymidori76@gmail.com
Guest
Posts: n/a
 
      20th Mar 2007
Good Morning S,

I'm getting close. Thank you so much in advance.

The code works - However it only works if I change the total header to
say "Total". The header may will vary from week to week. Can the
code work if it contains the value "Total".

Also, the row insertion needs a little tweaking. I've uploaded an
image of a better example.
ie

http://bp1.blogger.com/_0XguicNvp2w/...-h/example.bmp



 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      20th Mar 2007
Hi again

I have made it my goal today to get this right lol, anywho I think if
you use the code below it should work fine (we can but hope)

I changed the conditional statement to check the cells that contain a
value to see if the last 5 letters of the string contain either the
word Total or total if so then it will do run the code.

I also reset the iteration of the I integer as soon as the loop stops
which I think was the problem there.

Well give it a try see how it works out

Option Explicit
Dim MyCell, MyRng As Range
Dim i As Integer

Sub RunMyCode()
Set MyRng = [a1:a100] 'Set your range
For Each MyCell In MyRng
If MyCell.Value >= "" Then 'Check that cell has a value
If Right(MyCell, 5) = "total" Or Right(MyCell, 5) = "Total" Then
'Find last 5 letters in string
MyCell.Offset(1, 0).Select
Do While i < 4
ActiveCell.EntireRow.Insert
i = i + 1
Loop
i = 0 'Reset the counter here
ActiveCell.Value = "Avails"
ActiveCell.EntireRow.Interior.ColorIndex = 5
ActiveCell.Offset(1, 0).Value = "Left"
ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6
End If
End If
Next MyCell
End Sub

Steve



 
Reply With Quote
 
simplymidori76@gmail.com
Guest
Posts: n/a
 
      20th Mar 2007
Steve

Thank you so much. If you have an email account would you be able to
send.. I would like to send a little token.

This is working perfect...
I do have one more thing I forget to mention the text Avails & Left
could it moved over into column F. Is this a simple add to the
code?

You're the best.

Gwen

 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      20th Mar 2007
Hi Gwen

Glad it is up and running for you...

to move the text to column f just offset the activecell by 5 columns
like below.

ActiveCell.Offset(0,5).Value = "Avails"
ActiveCell.EntireRow.Interior.ColorIndex = 5
ActiveCell.Offset(1, 5).Value = "Left"
ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6

you can find address details on my profile

take it easy

Steve

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Formatting - Total column headings/rows Training Goddess Microsoft Excel Misc 0 31st Oct 2009 04:55 PM
how to get Text box calculation total added to a table field =?Utf-8?B?Um9ieQ==?= Microsoft Access Forms 4 21st Oct 2006 07:14 PM
HOW DO I RE-NUMBERED MY NUMBER COLUMN AFTER I ADDED ROWS? =?Utf-8?B?Q0FSQQ==?= Microsoft Excel Misc 1 14th Apr 2006 06:02 PM
Add total number of rows (text) in a column =?Utf-8?B?cm9zdHJvbmNhcmx5bGU=?= Microsoft Excel Worksheet Functions 1 15th Dec 2005 06:25 AM
macro - adding rows to a column that is summed HGood Microsoft Excel Misc 2 1st Dec 2004 03:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:12 AM.