Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to populate a new worksheet based on the value of a radio button. If radio button is enabled then I want "N" in a cell in a new worksheet along with the text label of that radio button. How do I reference the cell in which to store value and what are the classes I should call? Any sample code will definitely help in a tight time frame.
Posted
Updated 8-Mar-12 12:00pm
v2
Comments
Maciej Los 9-Mar-12 10:55am    
What have you done until now? Did you try google, support microsoft?

1 solution

If this is a question of VB, not VB.NET, the code below shows how to create instance of MS Excel application and how to write and read data.
VB
Option Explicit

Sub ReadWriteExcel()
'declare variables
Dim oExc As Object, oWbk As Object, oWsh As Object

'catch errors
On Error GoTo Err_ReadWriteExcel

'set variables
'instance od excel
Set oExc = CreateObject("Excel.Application")
'add workbook object
Set oWbk = oExc.Workbooks.Add()
'set worksheet object - first in the collection
Set oWsh = oWbk.Worksheets(1)

'write username to cell A1
oWsh.Range("A1") = Environ("username")
'read username from cell A1
MsgBox "Welcome " & oWsh.Range("A1") & "!", vbInformation, "Information..."

'exit procedure
Exit_ReadWriteExcel:
    'ignore errors
    On Error Resume Next
    'show excel if object Excel instance was successfuly created
    If Not oExc Is Nothing Then oExc.Visible = True
    'clean up
    Set oWsh = Nothing
    Set oWbk = Nothing
    Set oExc = Nothing
    Exit Sub

'error handler/error catcher
Err_ReadWriteExcel:
    'show message
    MsgBox Err.Description, vbExclamation, Err.Number
    'go to exit procedure
    Resume Err_ReadWriteExcel
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900