PC Review


Reply
Thread Tools Rate Thread

cell selection, merging.....

 
 
Steve
Guest
Posts: n/a
 
      31st Jul 2009
Ok, As stated in another post, I'm trying to make a macro for a selection of
cells based on a criteria.
In running it through, I'm finding that it selects increasingly larger cell
groupings.
I tried setting the variable to nothing, so as to "reset" it, for the
purpose of only grabbing the cells around which my criteria exists.

My core code is:

For Each rcell2 In Selection
If rcell2.Borders(xlEdgeBottom).LineStyle = xlSolid Then
ActiveSheet.Range(rcell1, rcell2).Select
With Selection
.Merge
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
End With
'Set rcell1 = Nothing
'Set rcell2 = Nothing
ActiveCell.Offset(1, 0).Select
'end if
End If
Next rcell2

If I use the set ... = nothing, it emtpies the variable, resulting in my
outermost if test to fail-- I get an object or with block not set error.

So, I need some code to empty the buffer of the value for my rcell1
variable-- so I can still retain its being a selection, but not have it
remember the original cell location.
What code would I use to accomplish this?

Thank you.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      31st Jul 2009
First, I would drop the .select's

For Each rcell2 In Selection
If rcell2.Borders(xlEdgeBottom).LineStyle = xlSolid Then
with ActiveSheet.Range(rcell1, rcell2)
.Merge
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
End With
'then maybe reset the rcell1
'maybe to the cell below the last rcell2
set rcell1 = rcell2.offset(0,1)
set rcell2 = nothing
end if
Next rcell2

But this is just a guess. I really don't know what rcell1 is used for.

Steve wrote:
>
> Ok, As stated in another post, I'm trying to make a macro for a selection of
> cells based on a criteria.
> In running it through, I'm finding that it selects increasingly larger cell
> groupings.
> I tried setting the variable to nothing, so as to "reset" it, for the
> purpose of only grabbing the cells around which my criteria exists.
>
> My core code is:
>
> For Each rcell2 In Selection
> If rcell2.Borders(xlEdgeBottom).LineStyle = xlSolid Then
> ActiveSheet.Range(rcell1, rcell2).Select
> With Selection
> .Merge
> .VerticalAlignment = xlCenter
> .HorizontalAlignment = xlCenter
> End With
> 'Set rcell1 = Nothing
> 'Set rcell2 = Nothing
> ActiveCell.Offset(1, 0).Select
> 'end if
> End If
> Next rcell2
>
> If I use the set ... = nothing, it emtpies the variable, resulting in my
> outermost if test to fail-- I get an object or with block not set error.
>
> So, I need some code to empty the buffer of the value for my rcell1
> variable-- so I can still retain its being a selection, but not have it
> remember the original cell location.
> What code would I use to accomplish this?
>
> Thank you.


--

Dave Peterson
 
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
Merging results from multi-selection fields RoMoM Microsoft Access Reports 0 6th Mar 2010 10:52 PM
Limiting selection in a cell AND linking that selection to a list Lisa Microsoft Excel Misc 1 28th Jul 2009 05:00 PM
How to create a selection list then display the selection in a cell gbjhavard@googlemail.com Microsoft Excel Programming 0 1st Aug 2007 03:01 PM
Merging into an Excel Cell the content of the Bookmarked table Cell from msword chamdan0150@netscape.net Microsoft Excel Discussion 1 6th Dec 2006 06:32 PM
Change from Column Selection to Cell Selection Lil Pun Microsoft Excel Programming 4 16th Jun 2006 10:38 PM


Features
 

Advertising
 

Newsgroups
 


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