PDA

View Full Version : auto addition of gridlines



skandi
06-29-2009, 07:25 AM
Hello all
I am sort of working on a "cool" macro.

this is what I have:

A spreadsheet called "P" in there are 2 columns "p1" and "p2"
now to begin with I have added borders to 4 rows below the heading.

so we have heading
"p1" "p2"
1 |__| ___|
2 |__| ___|
3 |__| ___|
4 |__| ___|

what I want the vba program to do is.. as soon as you come to the last cell (i.e row 4 of p2) I want it to automatically add a new row below with the borders.

So in other words, I need to check the following:

for the pseudocode lets assume p1 to be column A and p2 to be column B

so if B4 has text in it and HAS borders, insert an additional row below with the same border formating as row 4. If not, don't do anything.


I am having trouble writing the if statements. any help would be greatly appreciated.


-thanks
Skandi

skandi
06-29-2009, 07:37 AM
I already have a code that ads new rows but it is triggered by a hot key.

so I guess the thing to do would be to find the last row and last cell .. if that is the activecell, then trigger the hotkey... can someone tell me how to find that last row last column?

anandbohra
06-30-2009, 12:46 AM
This will help



http://www.ozgrid.com/VBA/ExcelRanges.htm

skandi
06-30-2009, 06:58 AM
I found this website before and it did help quite a bit... but I was only able to find the last cell used.. but now I am not able to use this to my advantage some how .. i need a macro that runs countinously. ..i.e. it has to continuously check if the cell I am typing in is the last cell or not ... how would I do that..???

Skandi

bryVA
06-30-2009, 09:46 AM
You could do something like this:

Private Sub Worksheet_SelectionChange(ByVal Target _
As Excel.Range)
If Target.Address = ***"Last Cell"*** Then
***Run Macro***
Else
End If
End Sub

Just use your macro that finds the last cell and use that to compare if the target address = the last cell. Then run a macro to do whatever you need.

Hope this helps,

mdmackillop
06-30-2009, 11:14 AM
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = Cells(Rows.Count, 2).End(xlUp).Row Then
Target.Offset(1, -1).Resize(, 2).Borders.LineStyle = xlContinuous
End If
End Sub