Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with Workbook_Open

Hello

Below is the code I run on Sheet 2 with a Worksheet_Change event. I would
like to run this code when the User opens the Workbook using the
Workbook_Open event. I am new to VBA, so any help will be greatly
appreciated.

Code from Sheet2 Module

Private Sub Worksheet_Change(ByVal Target As Range)

' Unprotecting Worksheet
Worksheets("Sheet 2").Unprotect Password:="1234"

' Unhide Rows before extracting Data
With Rows("9:409")
.EntireRow.Hidden = False
End With

' Target of Combo Box for Doctor List (F2)
If Target.Row = 2 And Target.Column = 6 Then

' Calculate criteria cell in case calculation mode is manual
Worksheets("Sheet 1").Range("AA2").Calculate
Worksheets("Sheet 1").Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet1").Range("AA1:AA2"), _
CopyToRange:=Range("A8:H8"), Unique:=False

' Hide Blank Rows
Worksheets("Sheet 2").Unprotect Password:="1234"
With Range("B9:B409")
.EntireRow.Hidden = False
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With
End If

' Protecting Worksheet
Worksheets("Sheet 2").Protect Password:="1234", Scenarios:=True

End Sub


Thanks in advance
Ruan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Help with Workbook_Open

Hi Ruan,

Ruan wrote:
Below is the code I run on Sheet 2 with a Worksheet_Change event. I would
like to run this code when the User opens the Workbook using the
Workbook_Open event. I am new to VBA, so any help will be greatly
appreciated.



I assigned the table sheets to the ranges.
Save thet following macro in a normally module:

Sub Ruan()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("AA2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("AA1:AA2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:H8"), Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

In the codemodule ThisWorkbook:

Private Sub Workbook_Open()
Ruan
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with Workbook_Open

Hello Melanie,

I entered your code as you showed, but I am receiving the following error -

"Compile error in hidden module: This workbook"

Here is my code that I entered in the Sheet 2 module
Sub DataFilter()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("BD2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("BD1:BE2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:AA8"),
Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

Thanks for your time
Ruan



"Melanie Breden" wrote in message
...
Hi Ruan,

Ruan wrote:
Below is the code I run on Sheet 2 with a Worksheet_Change event. I

would
like to run this code when the User opens the Workbook using the
Workbook_Open event. I am new to VBA, so any help will be greatly
appreciated.



I assigned the table sheets to the ranges.
Save thet following macro in a normally module:

Sub Ruan()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("AA2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("AA1:AA2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:H8"),

Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

In the codemodule ThisWorkbook:

Private Sub Workbook_Open()
Ruan
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Help with Workbook_Open

Hi Ruan,

Ruan schrieb:
I entered your code as you showed, but I am receiving the following error -

"Compile error in hidden module: This workbook"

Here is my code that I entered in the Sheet 2 module
Sub DataFilter()


you changed the procedure names of Ruan in DataFilter.
Did you also adapt in the Workbook_Open-Event?

Private Sub Workbook_Open()
DataFilter
End Sub


--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Help with Workbook_Open

Hi Ruan,

Ruan schrieb:
Hello Melanie,

I entered your code as you showed, but I am receiving the following error -

"Compile error in hidden module: This workbook"

Here is my code that I entered in the Sheet 2 module
Sub DataFilter()



the procedure does not belong into the codemodule of the table.
Provide in the VBE over Insert |Module a new module there and insert the procedure.
Is it now correct?

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with Workbook_Open

Ruan,

The new module, DataFilter, should be in a standard code module, not in the
ThisWorkbook module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Ruan" wrote in message
...
Hello Melanie,

I entered your code as you showed, but I am receiving the following

error -

"Compile error in hidden module: This workbook"

Here is my code that I entered in the Sheet 2 module
Sub DataFilter()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("BD2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("BD1:BE2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:AA8"),
Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

Thanks for your time
Ruan



"Melanie Breden" wrote in message
...
Hi Ruan,

Ruan wrote:
Below is the code I run on Sheet 2 with a Worksheet_Change event. I

would
like to run this code when the User opens the Workbook using the
Workbook_Open event. I am new to VBA, so any help will be greatly
appreciated.



I assigned the table sheets to the ranges.
Save thet following macro in a normally module:

Sub Ruan()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("AA2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("AA1:AA2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:H8"),

Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

In the codemodule ThisWorkbook:

Private Sub Workbook_Open()
Ruan
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with Workbook_Open

Hello Melanie,

I figure it out. I had the code in the Worksheet code module instead of the
General Code Module. Thanks so much for your help.

I need to add the following code, but seem to be getting an error -
Range("BA409:BD410").Copy Destination:=Range("A409")

It worked when I had it in this format -
Worksheets("Sheet 1").Range("BD2").Calculate
Worksheets("Sheet 1").Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Patient Data").Range("BD1:BE2"), _
CopyToRange:=Range("A8:AA8"), Unique:=False
Range("BA409:BD410").Copy Destination:=Range("A409")

I would greatly appreciate, if you could help me with this.
Thanks
Ruan



"Melanie Breden" wrote in message
...
Hi Ruan,

Ruan wrote:
Below is the code I run on Sheet 2 with a Worksheet_Change event. I

would
like to run this code when the User opens the Workbook using the
Workbook_Open event. I am new to VBA, so any help will be greatly
appreciated.



I assigned the table sheets to the ranges.
Save thet following macro in a normally module:

Sub Ruan()
With Worksheets("Sheet 2")
.Unprotect Password:="1234"
.Rows("9:409").Hidden = False

With Worksheets("Sheet 1")
.Range("AA2").Calculate
.Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("AA1:AA2"), _
CopyToRange:=Worksheets("Sheet 2").Range("A8:H8"),

Unique:=False
End With

With .Range("B9:B409")
' of case no empty cells available
On Error Resume Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.EntireRow.Font.ColorIndex = 1
End With

.Protect Password:="1234", Scenarios:=True
End With
End Sub

In the codemodule ThisWorkbook:

Private Sub Workbook_Open()
Ruan
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Help with Workbook_Open

Hi Ruan,

Ruan wrote:
I need to add the following code, but seem to be getting an error -
Range("BA409:BD410").Copy Destination:=Range("A409")


this command line alone does not produce an error message with me,
if the sheet is not protected.
How does the error message read exactly?

It worked when I had it in this format -
Worksheets("Sheet 1").Range("BD2").Calculate
Worksheets("Sheet 1").Range("Data_Log") _
.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Patient Data").Range("BD1:BE2"), _
CopyToRange:=Range("A8:AA8"), Unique:=False
Range("BA409:BD410").Copy Destination:=Range("A409")


It is better, if you call the Worksheet before each Range.
Before the points of the Range data the object of the With instruction is set automatically.

With Worksheets("Sheet 1")
.Range("BD2").Calculate
.Range("Data_Log").AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Patient Data").Range("BD1:BE2"), _
CopyToRange:=.Range("A8"), Unique:=False
.Range("BA409:BD410").Copy Destination:=.Range("A409")
End With


--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Sub Workbook_Open() doesn't run Steve Starr Excel Discussion (Misc queries) 4 April 3rd 11 05:05 AM
Breaking into Workbook_Open Bob Barnes Excel Discussion (Misc queries) 2 July 29th 09 10:45 PM
Workbook_Open () Bill Martin Excel Discussion (Misc queries) 12 December 20th 05 05:37 PM
Workbook_Open not working Sheena N via OfficeKB.com Excel Discussion (Misc queries) 4 May 6th 05 01:31 AM
Workbook_Open() error Ruan[_3_] Excel Programming 2 September 13th 03 09:13 PM


All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"