![]() |
| The AccuTerm forum has moved. Go to community.rocketsoftware.com to register for the new Rocket forum. |
|
Post Reply
|
| Author | |
pierre
Beta Tester
Joined: May 17 2006 Location: United States Status: Offline Points: 55 |
Post Options
Thanks(0)
Quote Reply
Topic: Set Range in ExcelPosted: December 20 2007 at 5:52am |
|
I've spent numerous hours googleling and searching this forum for a way to send a pick array to a range of cells in excel with no luck so I created my own version of it.
In order to do this you need to add this macro into your excel sheet: Sub SetRange(ByVal CurrentCell As String, ByVal Data As String) ' CurrentCell is the starting cell where the data will be copied to ' Data contains multi-valued data to be exploded into an array. ' @AM = '^' => Row delimiter ' @VM = ']' => Column delimiter ' @SVM = '\' => LF delimiter within a cell Dim col As Integer Dim row As Integer Dim DataArray() As Variant Dim x, y, n, nn, nn2 As Integer col = Range(CurrentCell).Column row = Range(CurrentCell).row s = Split(Data, "^", -1) n = UBound(s, 1) nn2 = -1 For x = 0 To n ss = Split(s(x), "]", -1) nn = UBound(ss, 1) If nn > nn2 Then ReDim Preserve DataArray(n, nn) End If For y = 0 To nn DataArray(x, y) = ss(y) Next y If nn > nn2 Then nn2 = nn Next x Range(Cells(row, col), Cells(row + n, col + nn2)) = DataArray Range(Cells(row, col), Cells(row + n, col + nn2)).Replace What:="\", Replacement:=Chr(10), LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False End Sub From your BASIC program do: CellPos = "A1" ;* This is the starting position * The dynamic array must be converted as follows CellData = SWAP(PickArray,@AM,"^") CellData = SWAP(CellData,@VM,"]") CellData = SWAP(CellData,@SVM,"\") SubName = 'SetRange' CALL ATINVOKEMETHOD(ExcelApplication, 'Run',SubName:@VM:CellPos:@VM:CellData,'', ERR, OPTS) IF ERR NE '' THEN CALL ATRESETOBJMGR;RETURN You can change the @AM, @VM and @SVM replacement characters to suit your needs. If you do, don't forget to change the BASIC code and the excel macro. This is a lot faster than sending data cell by cell. I hope this will be useful to someone. If you have a better way of doing this I'd love to hear it. Enjoy, Pierre |
|
![]() |
|
PSchellenbach
Admin Group
Moderator Joined: December 15 2003 Location: United States Status: Offline Points: 2150 |
Post Options
Thanks(0)
Quote Reply
Posted: December 21 2007 at 8:42am |
|
Thanks Pierre! This looks like it might be very useful! It also is a good example of extending the ObjectBridge functionality using Excel macros and the 'Run' method. I did not know Excel had this method! Good work!
Thanks, Pete |
|
![]() |
|
TonyG
Beta Tester
Joined: February 04 2004 Location: United States Status: Offline Points: 127 |
Post Options
Thanks(0)
Quote Reply
Posted: January 15 2008 at 10:57am |
|
Love to hear it? Check out NebulaXLite.
|
|
|
Tony Gravagno Nebula Research & Development
TG@ Nebula-RnD . com http://Nebula-RnD.com/blog http://Twitter.com/TonyGravagno http://groups.google.com/group/mvdbms https://www.linkedin.com/groups/64935 |
|
![]() |
|
pierre
Beta Tester
Joined: May 17 2006 Location: United States Status: Offline Points: 55 |
Post Options
Thanks(0)
Quote Reply
Posted: January 15 2008 at 2:27pm |
|
Ha! the question was "If you have a better way of doing this I'd love to hear it." so your answer is disqualified!
Plus, your solution requires addition costs (or is it free?). People with AccuTerm can do the same with a PickBASIC/Excel macro combo. ;-) |
|
![]() |
|
TonyG
Beta Tester
Joined: February 04 2004 Location: United States Status: Offline Points: 127 |
Post Options
Thanks(0)
Quote Reply
Posted: January 15 2008 at 4:07pm |
|
Ah, my brother from another mother...
NebulaXLite is free for non-production / developer use. Once it is deployed to an end-user system for production use, there is a one-time cost of $200. All support is free via our forum, many enhancements and all fixes are free. (I'm actually following Pete's model...) At some point a major release (or complimentary product with more extensions for Excel 2007) may be issued with many new features. This new release will be for sale on the same basis, essentially as a new product. For people who use AccuTerm on a daily basis and they and their end-users are still (after a decade) looking for a solution for "real" spreadsheets - NebulaXLite is not the same as the AccuTerm feature.
Coffee is on you next time. |
|
|
Tony Gravagno Nebula Research & Development
TG@ Nebula-RnD . com http://Nebula-RnD.com/blog http://Twitter.com/TonyGravagno http://groups.google.com/group/mvdbms https://www.linkedin.com/groups/64935 |
|
![]() |
|
lesley
Newbie
Joined: November 24 2010 Status: Offline Points: 1 |
Post Options
Thanks(0)
Quote Reply
Posted: December 01 2010 at 8:28am |
|
I've just found your post and it works perfectly for my application - as long as there are less than 150 attributes (or 9996 characters) in the array. If the array has more than 150 attributes, only the first 150 come into excel. Could this be a problem with the variable type? Is there a size limit?
Thanks! FYI..I found the problem - ATINVOKEMETHOD assumes the string will only have 9999 characters. Problem solved. :) |
|
![]() |
|
pierre
Beta Tester
Joined: May 17 2006 Location: United States Status: Offline Points: 55 |
Post Options
Thanks(0)
Quote Reply
Posted: December 04 2010 at 3:34am |
|
lesley,
I was not aware of the limitation. I've also never sent that much data that way! I do an import to load a lot of data to the sheet, I think it's a lot more efficient. |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |