From column format to multi column format in Excel VBA -
i have .txt data block-format :
1 1 2 2 3 3
in example have 3 blocks of size 2. size not vary blocks, fixed. real life case has around 500 block of size 500. import such data in excel format
1 2 3 1 2 3
that each column represent block. searching online tool provide simple simple copy-to-clipboard tool did not find any. how in excel vba given range of column , size of blocks (here range a1:a6 , block size 2) ?
sub tester() readblocks "c:\local files\tmp.txt", 100, activesheet.range("a1") end sub sub readblocks(spath string, blocksize long, rngdest range) dim fso object, f object, val, r long, c long on error goto haveerror set fso = createobject("scripting.filesystemobject") set f = fso.opentextfile(spath, 1) '1=forreading r = 0 c = 0 application.screenupdating = false application.calculation = xlcalculationmanual until f.atendofstream rngdest.offset(r, c).value = f.readline if (r + 1) mod blocksize = 0 r = 0 c = c + 1 else r = r + 1 end if loop haveerror: application.screenupdating = true application.calculation = xlcalculationautomatic end sub
Comments
Post a Comment