swap values in vba

CSmith

Well-known Member
Joined
Jan 13, 2020
Messages
614
Office Version
365, 2010, 2007
Platform
Windows, Mobile, Web
Post#4:
Thanks for your reply. If B has lets say 10 cells and A has 5 cells then after the swap column A will have 10 cells and column B will have 5 cells. Thanks once again
What about:
VBA Code:
[A:A].Cut
[C:C].Insert
Yes I did. So ?
Maybe you just don't know what your code actually does?? AFAIK moving the entire column is not 5 or 10 cells, or maybe I just have poor english skills?.
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,734
Post#4:
Maybe you just don't know what your code actually does?? AFAIK moving the entire column is not 5 or 10 cells, or maybe I just have poor english skills?.
My understanding (and Akiuni's) is that the OP wants to switch columns A & B regardless of how many cells are populated.
 

CSmith

Well-known Member
Joined
Jan 13, 2020
Messages
614
Office Version
365, 2010, 2007
Platform
Windows, Mobile, Web
Akuini did not seem to be doing the entire COLUMN only a portion of it...
VBA Code:
Range("A1:A" & n)
Is not an entire column.
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,734
Akuini did not seem to be doing the entire COLUMN only a portion of it...
VBA Code:
Range("A1:A" & n)
Is not an entire column.
His code covers all populated cells, as does mine.
Provided that columns A & B have the same formatting, his code and mine do the same thing.

With your code, it seems the source range and target range have to be the same size.
 

CSmith

Well-known Member
Joined
Jan 13, 2020
Messages
614
Office Version
365, 2010, 2007
Platform
Windows, Mobile, Web
His code covers all populated cells, as does mine.
Provided that columns A & B have the same formatting, his code and mine do the same thing.

With your code, it seems the source range and target range have to be the same size.
Incorrect.

My code will swap ONLY the range of cells specified. And will begin at top left cell per what seemed to be the OP's request and subsequent elaboration. I did not ask about overlapping ranges only assumed they would not overlap.
Thanks for your reply. If B has lets say 10 cells and A has 5 cells then after the swap column A will have 10 cells and column B will have 5 cells. Thanks once again
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,734
Incorrect.

My code will swap ONLY the range of cells specified. And will begin at top left cell per what seemed to be the OP's request and subsequent elaboration. I did not ask about overlapping ranges only assumed they would not overlap.
???
Anyway, let's wait to see what fits in with the OP's requirements.
It may be that I have misread the requirements or the OP only wants to add to her knowledge of VBA arrays - in which case my suggestion is inappropriate.
 

Forum statistics

Threads
1,085,157
Messages
5,382,049
Members
401,767
Latest member
JohnLeek

Some videos you may like

This Week's Hot Topics

Top