Visual Basic & Excel
#3
I'm trying to transfer the contents of a listbox into cells! SOunds simple but I've only just started with visual basic !
I have a drop down listbox and two list boxes. One listing options you add to the secondary box and then confirm. These options should then be input into a specific column based on the value in the drop down combo.
I have the correct code for the listboxes to add and remove options but how do I transfer the contents of the second listbox (listbox2) into the spreadsheet ?
Once these values from listbox2 are carried over I need to select another value from the dropdown combo which resets the contents of listbox2 so I can then select options again, these inturn are then transferred to another column on the spreadsheet.
ANy helpe appreciated !!!
Jai
I have a drop down listbox and two list boxes. One listing options you add to the secondary box and then confirm. These options should then be input into a specific column based on the value in the drop down combo.
I have the correct code for the listboxes to add and remove options but how do I transfer the contents of the second listbox (listbox2) into the spreadsheet ?
Once these values from listbox2 are carried over I need to select another value from the dropdown combo which resets the contents of listbox2 so I can then select options again, these inturn are then transferred to another column on the spreadsheet.
ANy helpe appreciated !!!
Jai
#4
Scooby Regular
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes
on
0 Posts
to get to all the elements in a listbox
for x=0 to list1.listcount-1
debug.print list1.list(x)
next x
to do the excel stuff
Dim objExcel As Excel.Application
Dim objWorksheet As Excel.Worksheet
Const XL_NOTRUNNING As Long = 429
Const Bold As Boolean = True
Const Regular As Boolean = False
Const Wrap As Boolean = True
Const NoWrap As Boolean = True
Sub OpenExcelSheet()
Set objExcel = Excel.Application
objExcel.Visible = False
objExcel.SheetsInNewWorkbook = 1
objExcel.Workbooks.Add
Set objWorksheet = objExcel.Worksheets("Sheet1")
end sub
Sub WriteCell(sText As String, lCol As Long, lRow As Long, sFontName As String, _
iFontSize As Integer, bBold As Boolean, sAlignment As String)
With objWorksheet
If Left(sText, 1) = "'" Then
.Cells(lRow, lCol).Value = sText
Else
.Cells(lRow, lCol).Formula = sText
End If
.Cells(lRow, lCol).Font.Name = sFontName
.Cells(lRow, lCol).Font.Size = iFontSize
.Cells(lRow, lCol).Font.Bold = IIf(bBold, True, False)
.Cells(lRow, lCol).VerticalAlignment = xlTop
.Cells(lRow, lCol).HorizontalAlignment = IIf(LCase(sAlignment) = "left", xlLeft, xlRight)
'.Cells(lRow, lCol).Font.Color = RGB(255,0,0)
End With
End Sub
Sub CloseExcelSheet(ByVal sFileName as string
objWorksheet.SaveAs FileName:=CloseExcelSheet, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
objExcel.Quit
Set objWorksheet = Nothing
Set objExcel = Nothing
End Function
[Edited by Fosters - 12/18/2002 2:47:25 PM]
for x=0 to list1.listcount-1
debug.print list1.list(x)
next x
to do the excel stuff
Dim objExcel As Excel.Application
Dim objWorksheet As Excel.Worksheet
Const XL_NOTRUNNING As Long = 429
Const Bold As Boolean = True
Const Regular As Boolean = False
Const Wrap As Boolean = True
Const NoWrap As Boolean = True
Sub OpenExcelSheet()
Set objExcel = Excel.Application
objExcel.Visible = False
objExcel.SheetsInNewWorkbook = 1
objExcel.Workbooks.Add
Set objWorksheet = objExcel.Worksheets("Sheet1")
end sub
Sub WriteCell(sText As String, lCol As Long, lRow As Long, sFontName As String, _
iFontSize As Integer, bBold As Boolean, sAlignment As String)
With objWorksheet
If Left(sText, 1) = "'" Then
.Cells(lRow, lCol).Value = sText
Else
.Cells(lRow, lCol).Formula = sText
End If
.Cells(lRow, lCol).Font.Name = sFontName
.Cells(lRow, lCol).Font.Size = iFontSize
.Cells(lRow, lCol).Font.Bold = IIf(bBold, True, False)
.Cells(lRow, lCol).VerticalAlignment = xlTop
.Cells(lRow, lCol).HorizontalAlignment = IIf(LCase(sAlignment) = "left", xlLeft, xlRight)
'.Cells(lRow, lCol).Font.Color = RGB(255,0,0)
End With
End Sub
Sub CloseExcelSheet(ByVal sFileName as string
objWorksheet.SaveAs FileName:=CloseExcelSheet, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
objExcel.Quit
Set objWorksheet = Nothing
Set objExcel = Nothing
End Function
[Edited by Fosters - 12/18/2002 2:47:25 PM]
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM