macro to merge two table cells?

I've trying unsuccessfully to record a macro that will merge a table cell 
with the cell to the right of it. Could anyone suggest code that would do 
this?
0
Utf
5/11/2010 9:12:01 AM
word.docmanagement 5542 articles. 2 followers. Follow

3 Replies
2025 Views

Similar Articles

[PageSpeed] 45

Sub MergeCellToRight()
Dim oRng As Range
Dim oCell As Cell
Dim i As Long
Set oCell = Selection.Cells(1)
If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
    MsgBox "There is no cell to the right?", vbCritical, "Error"
    Exit Sub
End If
Set oRng = oCell.Range
oRng.MoveEnd wdCell, 1
oRng.Cells.Merge
oCell.Select
Selection.Collapse wdCollapseStart
End Sub


will merge the cell containing the cursor with the cell to the right

-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"David Newmarch" <DavidNewmarch@discussions.microsoft.com> wrote in message 
news:D9E2F9CC-33E4-489F-BA68-2B7C44D85431@microsoft.com...
> I've trying unsuccessfully to record a macro that will merge a table cell
> with the cell to the right of it. Could anyone suggest code that would do
> this? 


0
Graham
5/11/2010 9:45:42 AM
Beautiful. Works like a charm. Thank you very much!

"Graham Mayor" wrote:

> Sub MergeCellToRight()
> Dim oRng As Range
> Dim oCell As Cell
> Dim i As Long
> Set oCell = Selection.Cells(1)
> If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
>     MsgBox "There is no cell to the right?", vbCritical, "Error"
>     Exit Sub
> End If
> Set oRng = oCell.Range
> oRng.MoveEnd wdCell, 1
> oRng.Cells.Merge
> oCell.Select
> Selection.Collapse wdCollapseStart
> End Sub
> 
> 
> will merge the cell containing the cursor with the cell to the right
> 
> -- 
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
> 
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 
> 
> "David Newmarch" <DavidNewmarch@discussions.microsoft.com> wrote in message 
> news:D9E2F9CC-33E4-489F-BA68-2B7C44D85431@microsoft.com...
> > I've trying unsuccessfully to record a macro that will merge a table cell
> > with the cell to the right of it. Could anyone suggest code that would do
> > this? 
> 
> 
> .
> 
0
Utf
5/11/2010 11:58:01 AM
You are welcome :) Note that the line
Dim i As Long
was not actually used in the posted version of the macro and can be deleted


-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

"David Newmarch" <DavidNewmarch@discussions.microsoft.com> wrote in message 
news:BA1272A8-FEC9-4229-953D-AB5EFD150463@microsoft.com...
> Beautiful. Works like a charm. Thank you very much!
>
> "Graham Mayor" wrote:
>
>> Sub MergeCellToRight()
>> Dim oRng As Range
>> Dim oCell As Cell
>> Dim i As Long
>> Set oCell = Selection.Cells(1)
>> If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
>>     MsgBox "There is no cell to the right?", vbCritical, "Error"
>>     Exit Sub
>> End If
>> Set oRng = oCell.Range
>> oRng.MoveEnd wdCell, 1
>> oRng.Cells.Merge
>> oCell.Select
>> Selection.Collapse wdCollapseStart
>> End Sub
>>
>>
>> will merge the cell containing the cursor with the cell to the right
>>
>> -- 
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor -  Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> "David Newmarch" <DavidNewmarch@discussions.microsoft.com> wrote in 
>> message
>> news:D9E2F9CC-33E4-489F-BA68-2B7C44D85431@microsoft.com...
>> > I've trying unsuccessfully to record a macro that will merge a table 
>> > cell
>> > with the cell to the right of it. Could anyone suggest code that would 
>> > do
>> > this?
>>
>>
>> .
>> 


0
Graham
5/11/2010 12:32:00 PM
Reply:

Similar Artilces:

Countif with two criteria?
Hi everyone What im trying to do is get some records that are Larger than (>) number and Smaller than (<) another number. I have tried using the COUNTIF statement but it only seems to let m use one criteria? format is: =COUNTIF(range,criteria) Anyone know if i can somehow use 2 criterias in this? or if not is there some other way i could do this? cheer ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com One way is to combine the Countifs: =COUNTIF(A1:A11,"&l...

Counting occurences of codes in cells
I have a spreadsheet with various codes separated by periods, in a single cell. Like: C T C,R T,C,R R and so forth. It's easy to count the single codes but how do I cound the "C" when it's with another character? There must be a simple way, without writing code, to do this. Is there? Thanks! maybe... =countif(a1:a10,"*" & "c" & "*") or =countif(a1:a10,"*c*") or if x99 contained the letter c. =countif(a1:a10,"*" & x99 & "*") salgud wrote: > > I have a spreadsheet with various codes separa...

Two equal subdatasheets visible under a datasheet?
Hello, I cannot get Access to display two hierarchically equal subdatasheets together when the form is in datasheet view. The both only are visible when the form is in single form view. tblCompanies tblEmployees tblPhoneNumbers tblEmailAddresses A company can have one or more employees. An employee can have one or more phone numbers AND one or more email addresses... Anything I'm missing, or is simply that Access cannot handle coequal datasheets? In datasheet view, a form can display only one subsheet at a time. But the subdatasheet property can easily be set with VBA code. One ...

same subform used in two different forms
Hi Folks, Is it possible to use the same subform in two different main forms simultaneously? If it's possible, is it good practice? I can foresee that there may be problems with code, but the subform I'm thinking of is very basic. Three tables: tblFamily FamID (primary key) FamLastName tblIndividual IndID (primary key) InFamID FirstName MiddleName ....other personal data tblAddress AddressID AdFamID street city state zip Two main forms for different types of data entry frmFamily with family information on the main form and address information...

Table of Content
I am trying to create a 3 level Table of Contend that looks like the following: 1.0 PURPOSE 1.1 Second Order Heading 1.2 Second Order Heading 1.3 Second Order Heading 1.3.1 Third Order Heading 1.3.2 Third Order Heading 1.4 Second Order Heading 2.0 PURPOSE The following macro gives me this: 1.0 PURPOSE 1.1 Second Order Heading 1.2 Second Order Heading 1.3 Second Order Heading 1.3.1 Third Order Heading 1.3.2 Third Order Heading 1.4 Second Order Heading 2.0 PURPOSE Here is my macro. How can I fix this? With ActiveDocument.Styles("...

create chart /table excel-save, close & reopen colors change? Why
When I create a chart/table in Excel - save, close & reopen to use again, the colors have changed for my formating. How do I set the formating so that the colors stay the same - I have tried styles with no luck. The colors need to be the company approved. Thank you, Anne, I am unable to reproduce yr problem. Excel should NOT override yr manual settings. However,you can set yr company colours as default under Tools/Options/[Color tab]. Here are the colours Excel uses by default for the workbook. (Under that thin line you see the defaults for fill and line colours.) Hope this...

Conditional Cell Category
Is it possible to make a cell's category conditional on the value in another cell? I would like to have a cell display its value as a currency if the cell before it says "Monthly", and as a percentage if the cell before it says "Annual". I am working in Excel 2003. Thank you, Trey ~ On 29 June, 15:39, one third <g...@hotmail.com> wrote: > Is it possible to make a cell's category conditional on the value in > another cell? > > I would like to have a cell display its value as a currency if the > cell before it says "Monthly", and as ...

What Excel macro puts data in the NEXT row of a sheet?
I have a list of data in col B of sheet 2 which I need to copy and transpose into sheet 1, then delete the data in sheet 2 to use the form again to copy and transpose onto the next line in sheet 1. I have tried with a macro shortcut I've called ctrl + e. (I am really using the data form process but cannot because I have too many inputs). Is there a simple macro I can copy and paste? ...

two contact folders disappeared. Where could they have gone?
Tried to open a contacts folder but it wouldn't open. Restarted outlook, saw the folder appear but then it disappeared before outlook fully loaded. Any idea where it could have gone? "Cloudburst" <Cloudburst@discussions.microsoft.com> wrote in message news:8696545F-26EE-43ED-A8BF-A48FBC6F0928@microsoft.com... > Tried to open a contacts folder but it wouldn't open. Restarted outlook, saw > the folder appear but then it disappeared before outlook fully loaded. Any > idea where it could have gone? Saw it appear where? What version of Outlook? Wha...

How to change cell data from all upper to title case
I need to change several columns of data from all upper case to Title Case. What formula should I use & How can I apply the formula to the data in each cell? Check out the Proper() function. It changes any case to title case, and can be copied from cell to cell to apply the formula to your data. Check out the Proper() function. It changes any case to title case and you can copy it to a range of cells to apply it to your data. You have other answers showing the use of the PROPER Function to act upon one cell at a time. If you want to change many cells at once you will need a mac...

2003 Macro not working in 2007
Can someone please help. I have macro for IE automation in 2003 but I do not know VBA. Here is the code that works in 2003 but will not run in 2007. Does anyone know what the new code would be for Excel 2007. This is the VBA code Dim objIE As Object Set objIE = CreateObject("InternetExplorer.Application") With objIE .Navigate "http://mywebsite.com" Do While .Busy: DoEvents: Loop Do While .ReadyState <> 4: DoEvents: Loop .Visible = True This is where Excel 2007 gets stuck. Do While .ReadyState <> 4: DoEvents: Loop Then it ge...

Table structure 04-07-10
I am having trouble getting my tables organized for their intended purpose. I am wondering if I am breaking them down too much. My first table is called: tblPMList and contains the following fields: MaintencanceID (This is an auto number and also the primary key) txtStructureNumber (4 unique numbers) txtStructureName txtPMCode (280 PM activities assigned to the structures, some unique, some alike) txtPMDesription (describes the work for the PM Code) txtPMType (Either mechanical or electrical) txtEquipmentNeeded (what equipment is needed to preform the PM) txtPMFrequency (1, 4, ...

determining macro status in a cell
Hi Is there a way to determine the status of macros (enabled or disabled within a cell formula? Thank -- Message posted from http://www.ExcelForum.com I don't believe this is possible. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "newengland >" <<newengland.11d8au@excelforum-nospam.com> wrote in message news:newengland.11d8au@excelforum-nospam.com... > Hi > > Is there a way to determine the status of macros (enabled or disabled) > within a cell formula? > > > Thanks > > > --...

line spacing in cell
I would like to type 3 pieces of text, each on a seperate line in one cell. I've looked under cell format Press Alt-Enter where you want to start a new line! Regards, Stefi „dlh” ezt írta: > I would like to type 3 pieces of text, each on a seperate line in one cell. > I've looked under cell format Thanks so much. Works great!! "Stefi" wrote: > Press Alt-Enter where you want to start a new line! > > Regards, > Stefi > > „dlh” ezt írta: > > > I would like to type 3 pieces of text, each on a seperate line in one cell. &...

Adding an Active X control to a cell
I would like to add a drop down lists to a bunch of cells. The control adds a box over the top of all the cells, trying to size it so that it fits over the top of the cell seems to be a rather inaccurate method of doing it. Hold down alt while you place it in the cell and it will fit the cell -- Regards, Peo Sjoblom "Rick" <rstenson@qualnetics.com> wrote in message news:317AA5B4-7970-45B2-8497-556670E48018@microsoft.com... > I would like to add a drop down lists to a bunch of cells. The control adds a box over the top of all the cells, trying to size it so that it f...

Can't see existing table in Design view for a QBE
Hi Guys, I can't see a table in QBE even when I have the scroll bar as far left as I possibly can. I have joineed another table to the query and I can see the relationship link but am unable to scroll left to view the table. Does anyone know how to fix this?? Many thanks in advance, Cheers, On Tue, 18 May 2010 17:35:01 -0700, DontKnow <DontKnow@discussions.microsoft.com> wrote: >Hi Guys, > >I can't see a table in QBE even when I have the scroll bar as far left as I >possibly can. I have joineed another table to the query and I can see the ...

combine hide row macro with conditional formatting
I'm sure one of you gurus can solve this in a flash. I've recorded a simple macro to hide a row (Alt O, Alt R, Alt H) but I want it to run automatically based on a cell value. For example: If cell value "A1" is "x" then I want the macro to run, and repeat itself down the column "A2, A3" etcetera until it reaches a blank cell. Is there a way to plug my existing macro "hiderow" into Conditional Formatting for a column; or is there a simpler solution? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.c...

Colouring cell if it has a specific date
Hi, I have a column for each month where the dates are entered on rows. Is it possible I can color a cell if the date entered in a cell for that month is 15 days past the end of the month. Like, if in a January column I enter a date on one of the rows as Feb.20, then the cell fills with red colour. I tried doing it using conditional formatting, but don't know how to say 15 days past end of the month? Any help will be appreciated! Thanks very much! Shivam Hi there Assuming 2007 If column A is January. I don't know where you have your reference date i.e. las...

Prefill Multiple Macro Buttons
I created a template and created multiple macro buttons where the user can click and type the appropriate information. There are several macro buttons that are the same and the user would have to key the information in several times. For example: [Click and type company name]. Is there a way to have the user type the company name once in that macro buttun and it prefills all the macro buttons that have [Click and type company name]? Thanks! Jlo See http://gregmaxey.mvps.org/Repeating_Data.htm -- <>>< ><<> ><<> <>>< ><...

Can I record a macro
....or do I have to write code manually? If so - how is that done? I think with Visio 2003, you can! Unfortunately, with Visio 2002 (which I have), this is not possible. Lana wrote: > ...or do I have to write code manually? > > If so - how is that done? > > Macro recording was introduced with Visio 2003. If you do not have Visio 2003, you can post a request to the newsgroups for someone to run the macro recorder and post the results. John... Visio MVP Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm Need VBA examples? http://www.mvps.org/visio/VBA...

crm4 workflow "Record attribute change" and merge Account record
Hi, Wondering if anyone can give me a work-around or tell me if this is a bug... Currently, I have a workflow that is defined to be triggered on Account "Record attribute change" condition. The attribute is a bit field, Yes or No. I have checked all Account records are set to "No". When I merge 2 Account records, the workflow fires, which I don't think it should. How can I work-around this? Many thanks! SW SW, Consider hotfix KB953821: http://support.microsoft.com/kb/953821 Peter Gernburd "SW" <SW@discussions.microsoft.com> wrote in message ...

Timestamp cell to left after update
For every row when cell C<whatever> is updated I need coresponding cell D<whatever> to update with a date time stamp until such a time that particular cell C is updated again. Been all over the place looking at macros worksheet functions etc. and nothing quite matches what I need. Currently I am using Ctrl-Shift-; followed by Ctrl-; to quickly enter this, but there has to be a way where I do not have to enter it all. Thanks in advance Hi see: http://www.mcgimpsey.com/excel/timestamp.html -- Regards Frank Kabel Frankfurt, Germany "Tahlmorrah" <Tahlmorrah@discus...

Two messages being scanned
When I send a single email, I notice two messages being scanned by Norton Anti-virus, but only one in the outbox. ...

Help with time over two days please?
HI thanks for looking, I have a sheet that I enter a start time into 12:30 PM (Cell formatted to time (Cell A1)) and a finish time of 2:30 AM (Cell formatted to time (Cell B1)) so I have worked a total of 14 hours. Can you please give me a formula that will work over the two days and also work if I start at 12:30 AM and finish at 10:30 PM on the same day IE 8 hours worked. Many thanks for your help Derek One way: Assuming the total time period is less than 24 hors, add 1 if the "later" time is less than the "earlier" time (since XL stores times as fractional...

Table of Contents Automatic Update
Is there a way that I can set the table of contents to automatically update like when I save or close a document? If so, how? Thanks! The following pair of macros should work: Sub FileSave() Dim t As TableOfContents For Each t In ActiveDocument.TablesOfContents t.Update Next t If ActiveDocument.Path = "" Then Dialogs(wdDialogFileSaveAs).Show Else ActiveDocument.Save End If End Sub Sub FileSaveAs() Dim t As TableOfContents For Each t In ActiveDocument.TablesOfContents t.Update Next t Dialogs(wdDialogFileSaveAs).Show End Sub Place the macros in the Normal ...