excel - Application defined error while copying a range of cells from a workbook to the workbook i have created in the code -


i got error @ starred lines. have browsed lot found many answers copied same still getting error . not sure of wrong doing.

please help. in advance.

sub splitintocsv()     dim wbin     dim wbin1 workbook     dim header, ranges, range_lower, range_upper, rangecopy variant     dim rangevariable string     dim commacheck, rows, columns integer      set wbin = createobject("excel.application")     wbin.workbooks.add     wbin.worksheets(1).name = "testdata"     set wbin1 = workbooks.open(sheet1.range("b1").value, true, true)      rows = wbin1.sheets(1).usedrange.rows.count     columns = wbin1.sheets(1).usedrange.columns.count     header = split(thisworkbook.sheets(1).range("b2").value, ",")     rangevariable = thisworkbook.sheets(1).range("b3").value     commacheck = instr(rangevariable, ",")      if commacheck = 0         rangevariable = rangevariable & ","     end if      ranges = split(rangevariable, ",")     = lbound(ranges) ubound(ranges) - 1         j = lbound(header) ubound(header)             wbin.worksheets(1).cells(1, j + 1).value = header(j)         next j          range_lower = split(ranges(i), "-")(0)         range_upper = split(ranges(i), "-")(1)          wbin1.sheets(1)            rangecopy = .range(.cells(1 + range_lower, 1), .cells(1 + range_upper, columns)).value         end          wbin.worksheets(1)             *********                     .range(.cells(1 + range_lower, 1), .cells(1 + range_upper, columns)).value = rangecopy           *********         end      next      wbin1.close savechanges:=true      wbin.displayalerts = false     wbin.worksheets(1).saveas filename:="d:\raghudev\raghu.csv", fileformat:=xlcsv, createbackup:=false     wbin.quit         end sub 

i don't same error can try following test in new excel report? i've tried recreate critical area of problem.

just sure put in sample data , select range of 1 3.

sub test()      dim wbin     set wbin = createobject("excel.application")     wbin.workbooks.add     wbin.worksheets(1).name = "testdata"      dim r variant, columns integer      r = selection.value     columns = 3      wbin.worksheets(1)         .range(.cells(1, 1), .cells(1, columns)).value = r     end  end sub 

also try define variants:

redim rangecopy(1 (range_upper - range_lower + 1), 1 columns) variant  wbin1.sheets(1)    rangecopy = .range(.cells(1 + range_lower, 1), .cells(1 + range_upper, columns)).value end  wbin.worksheets(1)       .range(.cells(1 + range_lower, 1), .cells(1 + range_upper, columns)).value = rangecopy end 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -