excel - VBA Columns Automatically Merge? -


I am writing a program in VBA, which first composes the range before a series of cells and then later the loops To collect data in cells.

The problem is that I need a limit to maintain that order in which I add the cells so that I can collect the data in the correct order, when I want to return, if the data are in the column , Then it is imminent, so the range transforms it into a heap of rows.

This means that if you run this program:

sub test_function ()

range as a dim My_Range

My_Range = association (ActiveSheet.Range ("A1: A5")

), ActiveSheet.Range ("B1: B5"))

Set to My_Range for each My_Cell

  i = I + 1 My_Cell.Value = i  My_Cell 

Next sub sub

You can see that the boundary is compiled of two adjacent columns of data (A1: A5 and B1 : B5), but this appendix Instead of known output:

1 6

2 7

3 8

4 9

5 10

You

1 2

3 4

5 6

9 10

9 10

This will reproduce this behavior even if you set My_Range = ActiveSite. ("A1") set My_Range = Union (My_Range, ActiveSheet.Range ("A2")) Set My_Range = Union (My_Range, ActiveSheet.Range ("A3")) etc ...

Is there a range to preserve a sequence? Or is the only way to different adjacent boundaries? At the very least (if I can not get it to preserve the exact sequence), then do any of its ways before and after?

- Daniel

I would recommend creating a collection of categories, , Which will preserve the sequence in which the categories were included. Example: -

(untested code)

  Add new collection categories as a dim border. (Categories, numbers, ActiveSheet.Range ( "A1") category (Categories, ActiveSheet.Range ("C6") // etc. etc. You can also loop through the categories in which they were added as RGR category , Do something with each RG category / range in them. Next RG / You can also get the reference of the Union if you Dim Union Range Range set union as want category = ranges (0) set Range for RG 2 category in RG 2 category as Union Range = Application.Union (unionRange, rg2) Next rg2 // Union  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -