1 time you know it, then an error or it do nothing...... can someone tell me what is wrong with my code?
problem: i cant print my msflexgrid into excell in sheet no.2
i added this and it do nothing, no errors just it does not do a single thing...Code:Dim iRow As Long Dim iCol As Long Dim newcell As String Dim lastcol As Range Dim currentcell As Range Dim xls As excel.Application Dim XLSbook As excel.Workbook Dim xlssheet As excel.Worksheet Const xlCellTypeLastCell As Long = 11 Set xls = New excel.Application Set XLSbook = xls.Workbooks.Open(App.Path & "\book1.xls") DoEvents For iRow = 0 To MSFlexGrid1.Rows - 1 For iCol = 0 To MSFlexGrid1.Cols - 1 MSFlexGrid1.Col = iCol MSFlexGrid1.Row = iRow newcell = Chr(iCol + 65) & iRow + 1 xls.Worksheets("sheet1").Range(newcell).Value = Trim(MSFlexGrid1.Text) Next Next 'AutoFormat xls.Selection.AutoFormat Format:=xlRangeAutoFormatList1 'Center all in A With xls .Worksheets("sheet1").Columns("A:A").Select Selection.HorizontalAlignment = xlCenter End With 'center all in B With xls .Worksheets("sheet1").Columns("B:B").Select .Selection.HorizontalAlignment = xlCenter End With 'Center all in E xls.Worksheets("sheet1").Columns("E:E").Select With xls.Selection .HorizontalAlignment = xlCenter End With xls.Selection.Style = "Currency" 'last column of E put the lblfishvalue Range("E1").SpecialCells(xlCellTypeLastCell).Offset(1) = lblFishValue.Caption Range("D1").SpecialCells(xlCellTypeLastCell).Offset(0, -1).Value = "Fish Value Total =" 'for sheet 2 DoEvents For iRow = 0 To FrmCharges.MSFlexGrid1.Rows - 1 For iCol = 0 To FrmCharges.MSFlexGrid1.Cols - 1 MSFlexGrid1.Col = iCol MSFlexGrid1.Row = iRow newcell = Chr(iCol + 65) & iRow + 1 xls.Worksheets("sheet1").Range(newcell).Value = Trim(FrmCharges.MSFlexGrid1.Text) Next Next 'Save workBook as ReadOnly File with password XLSbook.SaveAs ("C:\Documents and Settings\coa\My File.xls"), , , ("123"), (True), , (xlShared), (xlUserResolution) 'show excel book xls.Visible = True 'close Set XLSbook = Nothing Set xls = Nothing
Code:DoEvents For iRow = 0 To FrmCharges.MSFlexGrid1.Rows - 1 For iCol = 0 To FrmCharges.MSFlexGrid1.Cols - 1 MSFlexGrid1.Col = iCol MSFlexGrid1.Row = iRow newcell = Chr(iCol + 65) & iRow + 1 xls.Worksheets("sheet2").Range(newcell).Value = Trim(FrmCharges.MSFlexGrid1.Text) Next Next




Reply With Quote