If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > To create a new dialog box

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-09, 04:02
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
To create a new dialog box

Hi Techies!,

I'm not technically trained in writing program in visual basic. I'm aiming to write a macro in VB, to display the information in excel in a new dialog box at a click of the button.

for e.g; sum(A11:A30) should be displayed in a new dialog box.

can someone help me
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #2 (permalink)  
Old 02-26-09, 05:58
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
Dim rng As Range

With ActiveSheet
    Set rng = .Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp))
End With

MsgBox Application.WorksheetFunction.Sum(rng)
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 02-26-09, 23:57
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
George Thank you very much indeed!!!
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #4 (permalink)  
Old 02-27-09, 03:17
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
To create a dialog box

George,

Thank you.

The code you have given is working fine. But it looks so simple. I have created a structure of the dialog box as how it should appear. pls find the same in the attached word file.

i will await your reply.

thx
Attached Files
File Type: doc Dialog Box.doc (26.5 KB, 90 views)
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #5 (permalink)  
Old 02-27-09, 05:16
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I don't know how to assign values to controls in Excel, check out the helpfiles.
This code should hel you on your way though
Code:
Dim a As Integer
Dim g As Integer

'Sheet 1                                          \|/
a = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("A1:A10"))
g = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("G1:G10"))

MsgBox "A = " & a
MsgBox "G = " & g
MsgBox "Diff: " & a - g

'Sheet 2                                          \|/
a = Application.WorksheetFunction.Sum(Sheets("sheet2").Range("A1:A10"))
g = Application.WorksheetFunction.Sum(Sheets("sheet2").Range("G1:G10"))

MsgBox "A = " & a
MsgBox "G = " & g
MsgBox "Diff: " & a - g
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 02-27-09, 07:33
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
to create a new dialog box

George,

Thank you. It is giving the result only for sheet1 and not for sheet2.

I expect the result to be in the form and layout i have prescribed in the word document.

regards,
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #7 (permalink)  
Old 03-02-09, 03:29
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Hi Ganesh,

I'm afraid the above is the extent of my Excel knowledge - hopefully you can work with what's been provided so far and complete the last steps.
__________________
George
Twitter | Blog
Reply With Quote
  #8 (permalink)  
Old 03-02-09, 06:10
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
Hi Goerge,

No worries. Thank you!
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #9 (permalink)  
Old 03-04-09, 05:24
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
Hello Marsh,

Thanks for your reply.

Cud you pls be more specific on your description?

I don't understand what you have specified.

regards,
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #10 (permalink)  
Old 03-05-09, 02:04
Chris Bode Chris Bode is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
1.Right click on the toolbar, from the popup select control box
2.From the control box that appears on the sheet1, select and draw a command button on the sheet1
3.Double click the command button to open the code window and paste following codes

Code:
Private Sub CommandButton1_Click()
    Dim row As Integer, col As Integer
    row = 11
    col = 1
    
    Dim sum As Double
    sum = 0
    
    For row = 11 To 30
        sum = sum + CDbl(Sheet1.Cells(row, col).Value)
    Next
    
    MsgBox sum
End Sub
Reply With Quote
  #11 (permalink)  
Old 03-05-09, 09:19
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
Chris,

Thanks for your reply.

I expect the appearance of the dialog box to be in the form i have prescribed in the word document...

cud you pls help me?

regards,
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #12 (permalink)  
Old 03-05-09, 09:33
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Ganesh,

Are you able to assign a value to those boxes programatically yourself?
Something like
Code:
control_name.value = "test"
__________________
George
Twitter | Blog
Reply With Quote
  #13 (permalink)  
Old 03-05-09, 10:52
ganeshdlegend ganeshdlegend is offline
Registered User
 
Join Date: Feb 2009
Posts: 24
George,

I'm sorry... I donot know how to assign values to the controls.... I'm completely ignorant...

It is not nessasary that the dialog box should be in the same structure i have mentioned in the word dcument. It have just conveyed my idea...

You can rework and bring it to your convenience as well. But it should convey the SUM(A1:A10) and SUM(G1:G10) and the difference in one single msg box but not sequential.

I'm glad that you are looking forward to help me again...

Thanks,
__________________
Ganesh
Everyone is gifted! Some open the package sooner!
Reply With Quote
  #14 (permalink)  
Old 03-06-09, 01:15
Chris Bode Chris Bode is offline
Registered User
 
Join Date: Feb 2009
Posts: 6
Use following code for the design of the user form1 that you have given in word document

Code:
Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOK_Click()
    txtSumA1A10.Text = CStr(sheet1SumA1A10)
    txtSumG1G10.Text = CStr(sheet1SumG1G10)
    
    txtDiffSheet1.Text = CStr(sheet1SumA1A10 - sheet1SumG1G10)
    
    txtSheet2SumA1A10.Text = CStr(sheet2SumA1A10)
    txtSheet2SumG1G10.Text = CStr(sheet2SumG1G10)
    
    txtDiffSheet2.Text = CStr(sheet2SumA1A10 - sheet2SumG1G10)
End Sub

Private Function sheet1SumA1A10() As Double
    Dim row As Integer, col As Integer
    col = 1
    
    Dim sum As Double
    sum = 0
    For row = 1 To 10
        sum = sum + CDbl(Sheet1.Cells(row, col).Value)
    Next
    sheet1SumA1A10 = sum
End Function

Private Function sheet1SumG1G10() As Double
    Dim row As Integer, col As Integer
    col = 7
    
    Dim sum As Double
    sum = 0
    For row = 1 To 10
        sum = sum + CDbl(Sheet1.Cells(row, col).Value)
    Next
    sheet1SumG1G10 = sum
End Function

Private Function sheet2SumA1A10() As Double
    Dim row As Integer, col As Integer
    col = 1
    
    Dim sum As Double
    sum = 0
    For row = 1 To 10
        sum = sum + CDbl(Sheet2.Cells(row, col).Value)
    Next
    sheet2SumA1A10 = sum
End Function

Private Function sheet2SumG1G10() As Double
    Dim row As Integer, col As Integer
    col = 7
    
    Dim sum As Double
    sum = 0
    For row = 1 To 10
        sum = sum + CDbl(Sheet2.Cells(row, col).Value)
    Next
    sheet2SumG1G10 = sum
End Function
Reply With Quote
  #15 (permalink)  
Old 03-06-09, 05:40
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
Dim a As Integer
Dim g As Integer

Dim msg As String
msg = ""

a = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("A1:A10"))
g = Application.WorksheetFunction.Sum(Sheets("sheet1").Range("G1:G10"))

msg = msg & "Sheet1(A1:A10) = " & CStr(a) & Chr(13)
msg = msg & "Sheet1(G1:G10) = " & CStr(g) & Chr(13)
msg = msg & "Difference     = " & CStr(a - g) & Chr(13)  & Chr(13)

a = Application.WorksheetFunction.Sum(Sheets("sheet2").Range("A1:A10"))
g = Application.WorksheetFunction.Sum(Sheets("sheet2").Range("G1:G10"))

msg = msg & "Sheet2(A1:A10) = " & CStr(a) & Chr(13)
msg = msg & "Sheet2(G1:G10) = " & CStr(g) & Chr(13)
msg = msg & "Difference     = " & CStr(a - g)

MsgBox msg
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On