VBA Code to select and format range

Hi All,

I want to select a range of cells and format the range of cells based on a 
"offset" feature...

The last couple lines in my code are:

    ActiveCell.Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"

Where the active cell reference is a moving target depending on the amount 
of data in the worksheet.  How do I now say - select this cell, plus other 
cells in this range of cells and format them with a border, and a color?  I 
can't get the syntax right.  I I record the macro, it only gives me this:     
 range("I32:L37").Select -which is not what I want....

Thanks for the help..

-- 
Thanks for all of the help.  It is much appreciated!!!!
-1
Utf
6/7/2010 7:11:04 PM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
2604 Views

Similar Articles

[PageSpeed] 42

Bean Counter has brought this to us :
> Hi All,
>
> I want to select a range of cells and format the range of cells based on a 
> "offset" feature...
>
> The last couple lines in my code are:
>
>     ActiveCell.Offset(1, 0).Select
>     ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"
>
> Where the active cell reference is a moving target depending on the amount 
> of data in the worksheet.  How do I now say - select this cell, plus other 
> cells in this range of cells and format them with a border, and a color?  I 
> can't get the syntax right.  I I record the macro, it only gives me this:     
>  range("I32:L37").Select -which is not what I want....
>
> Thanks for the help..

This is what I got when I ran the macro recorder:

Sub Macro2()
    Range("I32:L57").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection.Interior
        .ColorIndex = 35
        .Pattern = xlSolid
    End With
End Sub

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


0
GS
6/7/2010 7:36:02 PM
      If desired, send your file to my address below. I will only look if:
      1. You send a copy of this message on an inserted sheet
      2. You give me the newsgroup and the subject line
      3. You send a clear explanation of what you want
      4. You send before/after examples and expected results.


-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Bean Counter" <BeanCounter@discussions.microsoft.com> wrote in message 
news:98B11A0F-D7F8-42E7-8E54-63587286B7BC@microsoft.com...
> Hi All,
>
> I want to select a range of cells and format the range of cells based on a
> "offset" feature...
>
> The last couple lines in my code are:
>
>    ActiveCell.Offset(1, 0).Select
>    ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"
>
> Where the active cell reference is a moving target depending on the amount
> of data in the worksheet.  How do I now say - select this cell, plus other
> cells in this range of cells and format them with a border, and a color? 
> I
> can't get the syntax right.  I I record the macro, it only gives me this:
> range("I32:L37").Select -which is not what I want....
>
> Thanks for the help..
>
> -- 
> Thanks for all of the help.  It is much appreciated!!!! 

0
Don
6/7/2010 8:50:03 PM
Reply:

Similar Artilces:

How to Stop Worksheet_Change event from running during code execution
I'm sorry If I've asked this before but I can't find an answer to it. I have the following 2 events in a worksheet module.... Private Sub Worksheet_Change(ByVal Target As Excel.Range) Private Sub Worksheet_SelectionChange(ByVal Target As Range) I run some codes, either in UserForms or general procedures that make changes to this worksheet. Q. Is there a way to by-pass those two events somehow? As an example I have a uf that comes up if a cell is selected in that sheet. So I need those worksheet_Change events to work at that point. But then, the uf does some stuff like inputing ...

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

Payout reason codes
Can someone point me to where in the database the payout reason codes are stored? thanks, Store Ops Manager, Database, Reason Codes, Type = Payout "Jason" wrote: > Can someone point me to where in the database the payout reason codes are > stored? > > thanks, Thanks. What I meant (and asked poorly) was if I wanted to design a custom report to show that info where would I need to look? Thanks, "Wendy_I" wrote: > Store Ops Manager, Database, Reason Codes, Type = Payout > > > > "Jason" wrote: > > > Can someo...

Sort several workbooks using code
I am looking to run code that will sort several workbooks even when they are closed. The code would be executed via a master workbook which will also be sorted. Is this possible? I'm not aware of sorting records in a CLOSED workbook, but what you can do is this. Create some button on the master workbook and let it open the other workbook, sort the other workbook and close the other workbook. Accompanied with Application.ScreenUpdating (but also depending on the amount of records) you will hardly notice the sorting actions. Does this help ? -- Regards; Mark ...

BROWSEINFO: set (pre)selected path
Hi together, in C++.net I can do the following in a FolderBrowserDialog for the user to change f.e. the workPath for an application: FolderBrowserDialog* di=new FolderBrowserDialog(); di->RootFolder = Environment::SpecialFolder::Desktop; di->SelectedPath=workPath; In an MFC project I can do the following: BROWSEINFO bi; bi.pidlRoot = NULL; // set root to user's desktop But I did not find any possibily to pre(select) the old workPath in then structure: typedef struct _browseinfo { HWND hwndOwner; LPCITEMIDLIST pidlRoot; LPTSTR pszDisplayName; LPCTSTR lpszTi...

POS Receipt format change
I would like to have the "Sales Receipt" read "Sales Invoice" or "Invoice". Also I would like to have "Transaction #" replaced with "Invoice #". Can anyone help me with this? I have been able to edit the "Sales Receipt" portion in an xml editor but have not been able to change the "Transaction #" as there must be some other coding that needs to change. Thank you in advance. Robert Hi Robert, you can find the SUB: PrintTransactionType and then locate the Transaction.ReceiptReferenceNumberCaption reference field. this...

Print, Merged Cells, and VBA
Hello I'm looking for a code that will help me with a print job for a worksheet. There are a lot of merged cells and a lot of "IF"s to be used in the VBA for range selection. Thanks in advance, Sarr ...

Group / Ungroup Text Range
Hi - Have a template with a form in Word that is protected with Group (Under Developer ribbon). Also need to show spell check so I'm using Rich Text Boxes. To protect - selected the table they are in and used Group under the Developer ribbon. The user can click on a macro button and generate more of the same rich text boxes. (Kind of like an order form) I had to add font to the boxes because the print was coming out gray instead of black. The problem is I went to add font to the duplicate boxes and an error comes up: "Run-time error 4605. This method or property ...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

Conditional Formatting Need
Please Help, I really tried on my own. Column A and Column B If the cell value in column A1 is <6 format should be Blank If it is 6.0-6.99 then it will look to B1 for more info If it is 7-0-7.99 then it will look to B1 for more info And if it is 8 or greater it will look to B1 for more info If A1�s value is 6 or greater it is possible it will still remai blank, but now it will look to B1 for that value, to determine wha should happen with A1 If B1 is greater than 2.99 then A1 will remain blank and also B1 wil be blank If B1 is between 2.0 and 2.99 and A1 is between 6 and 7.99 the forma...

RE: Yes/No select All or select None
I have a form (continuous) where the user sees a list of all people with a yes/no checkbox beside the name. They can scroll down the list and select individuals by clicking on the Yes/No checkbox. I would like to add a button that allows the user to select all or to unselect all (select none). Any thoughts on how to accomplish this? Thank you, Kelvin Execute an Update query to set the field to Yes or No for all records. Here's the kind of code you would put into the Event Procedure for the Click event of your command button: Dim strWhere As String 'Save any changes...

My selections are locked--how do I unlock them?
I'm using Microsoft Office Home and Student 2007 and the bottom of my page says that my selections are locked. This happens when I try to do anything. The only thing I can do is open a document, but it won't let me type or copy or anything like that. Also, little paragraph symbols have appeared all over my page. Is it a trial copy that has expired? If so, time to buy. Is it a retail copy that hasn't been actived? "ChikiMongo" <ChikiMongo@discussions.microsoft.com> wrote in message news:B791BF17-B602-4297-9AED-FB3FF4F976D9@microsoft.com... : I'm...

wav file format
Hello, I am trying to write a *.wav file. I read about its format and now I can write a *.wav file but when I am trying to play it with Media player, it reports that the file is corrupted which I think means that there is a problem on the file format but I couldn't find what is it. Is there any application that could read a wav file and report if there is any problem in its format? Is there any code that helps me to find what I can use to write a wav file? Any help is very appreciated. Best regards Have you seen www.wotsit.org? "ma" <ma@nowhere.com> wrote i...

How get rid of reveal codes?
How get rid of reveal codes? the symbols are all over my document!! How do I get rid of them?? Try:- ALT + F9 If my comments have helped please hit Yes. Thanks. "Christa" wrote: > How get rid of reveal codes? the symbols are all over my document!! How do > I get rid of them?? Ctrl+* or Ctrl+Shift+8. See http://word.mvps.org/FAQs/Formatting/NonPrintChars.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Christa" <Christa@discussions.microsoft.com> wrote in mes...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

Column width and pasting sections in excel? Formatting questions
I am trying to make a spreadsheet in which I need to have varied column widths in different sections, one under another. (they don't need to relate directly, and no major equations going on) for example: xxxxxxxxx|xxxxxxxxxx xxxxxxxxx|xxxxxxxxxx xxxxxxxxx|xxxxxxxxxx xxxxxxx|xxxxx|xxxxxx xxxxxxx|xxxxx|xxxxxx How do I go about splitting the sheet or whatever I need to do so I can manipulate columns differently based on the row I'm in? Thanks! Rich Column widths apply to the whole column. You may be able to use merged cells to give the appearance that you want, but I try to stay...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

Number Format #10
Hello I've got a large spreadsheet which was imported. Apart from the first 2 columns, the rows consist of number which I need to filter, but this isn't working. Then I noticed an apostrophe before each number in every cell, which doesn't show in the cell but up in the formula/text bar. I've set all the columns to numbers but the apostrophe won't go away. Please can someone tell me how I can without having to go into each cell as there are hundreds. Thank you J Select all the columns with these "numbers" in them, then right click the tab at the bottom of t...

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

Loading a Form from VBA
Hi all, I'd like a module to open and load a form in my Access 2003 database... How can I do this? Use the OpenForm method. Look in the Help file for details. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mike" <michael.leon.schwartz@gmail.com> wrote in message news:1184770076.109526.207900@o11g2000prd.googlegroups.com... > Hi all, I'd like a module to open and load a form in my Access 2003 > database... How can I do this? > On Jul 18, 10:58 am, "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com&g...

Multiple Formula Custom Formatting
I was recently challenged to create a formula that displays two values separated by a slash in the same cell. For example A1=40 and B2= 10. C3 displays [30 / .75]. The difference between the two, and what should be the percentage. The formula I put together is =(A1-B2)&" / "&((A1-B2)/A1). The formula works but I can not get the second value to format as a %, it only displays as a decimal. Does anyone know how I can make the second value display as a percentage without messing up the formatting of the first value? Any advice would be much appreciated. ...

Excel and VBA
I am very interested in learning more about using VBA in office, especially Excel. Can you post some resources (online, books, etc) that can be used to help learn about using Visual Basic in office. Thanks! Here's a good place to start: http://www.contextures.com/xlbooks.html Does that help? *********** Regards, Ron XL2002, WinXP "Bob Sinclair" wrote: > I am very interested in learning more about using VBA in office, especially > Excel. Can you post some resources (online, books, etc) that can be used to > help learn about using Visual Basic in office. >...

VBA Customization
Is there a way to get the name of the current company through VBA in Great Plains 8.0? Thanks for all your help. open GreatPlains. Add the current window, it will add the Toolbar then add fields choose the company name on the top left after the user id. >-----Original Message----- >Is there a way to get the name of the current company through VBA in Great >Plains 8.0? > >Thanks for all your help. > > > >. > Thanks. I tried, but I couldn't add company name to the field list. It opens up the login screen instead. Any thoughts? Thanks again. "ger...