VBA Help Please

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator: Moderators

Post Reply
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

VBA Help Please

Post by Positron »

What I want to do is to call(run) a subroutine from another subroutine that is on a different sheet.
Last edited by Positron on Sun Apr 27, 2008 11:24 pm, edited 1 time in total.
jeffslot
Portablizer Extraordinaire
Posts: 853
Joined: Wed Jun 01, 2005 6:26 am
Location: PA
Contact:

Post by jeffslot »

Positron,

On Sheet two I made a sub procedure similar to below:

Code: Select all

Public Sub SayHello()
MsgBox "Hello World"
End Sub
Then behind my command button on sheet one I used:
Private Sub CommandButton1_Click()
Call Sheet2.SayHello
End Sub
I hope this is what you meant. This works for me.
What I want to do is to call(run) a subroutine from another subroutine that is on a different sheet.
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

Post by Positron »

Ok. I got your example to work but when I implement it to mine it gives me the "Object Required" error...
jeffslot
Portablizer Extraordinaire
Posts: 853
Joined: Wed Jun 01, 2005 6:26 am
Location: PA
Contact:

Post by jeffslot »

Is it possible you aren't calling the sheet by the right name?
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

Post by Positron »

Thank you for your help. I think that's what it was... I just added Worksheets("Sheet1").Activate, plus your example and it did it.... WOW... Thank you, I was getting very frustrated.
jeffslot
Portablizer Extraordinaire
Posts: 853
Joined: Wed Jun 01, 2005 6:26 am
Location: PA
Contact:

Post by jeffslot »

:D
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

Post by Positron »

I hit another snag.... I need a macro that removes a border of a cell.
jeffslot
Portablizer Extraordinaire
Posts: 853
Joined: Wed Jun 01, 2005 6:26 am
Location: PA
Contact:

Post by jeffslot »

Positron,

This should be pretty easy, & I'll be more than happy to help you. Did you know that you can 'Record' a macro & then simply look at the generated code?

Let me know.

Jeff
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

Post by Positron »

I am not quite sure what the record feature does. How do I use it correctly? How will it help me? Thanks again.
jeffslot
Portablizer Extraordinaire
Posts: 853
Joined: Wed Jun 01, 2005 6:26 am
Location: PA
Contact:

Post by jeffslot »

Well If I

* select Tools-->Macro-->Record New Macro from the tool bar &
* click on OK to start the recording.
* Select any cell
* Right-click & select Format Cells from the pop up menu.
* Click on the Border Tab
* Click on the NONE preset.
* Click on OK to close the format cells dialog.
* Go to Tools-->Macro-->Stop Recording
* Go to the visual basic editor
* Double-click on the Module1 I can see code similar to:

Code: Select all

Sub Macro1()

Selection.Borders(xlDiagonalDown).Linestyle =  xlNone
Selection.Borders(xlDiagonalUp).Linestyle =  xlNone
Selection.Borders(xlEdgeLeft).Linestyle =  xlNone
Selection.Borders(xlEdgeTop).Linestyle =  xlNone
Selection.Borders(xlEdgeBottom).Linestyle =  xlNone
Selection.Borders(xlEdgeRight).Linestyle =  xlNone
Selection.Borders(xlInsideVertical).Linestyle =  xlNone
Selection.Borders(xlInsideHorizontal).Linestyle =  xlNone

End Sub
I end up with the code that can remove the border of a cell. Of course you could always spruce up this code if you wanted, maybe use a with statement to cut down on redundant code, but it should still get the job done.
Positron
Posts: 53
Joined: Mon Mar 31, 2008 11:10 pm

Post by Positron »

Cool! The record feature should help me with most of my future problems. Thanks for all your help.
Post Reply