LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default passing variables

I created some code in the workbook_open event that
worked great. Basically, when workbook1 opens it opens
workbook2 and copies its contents, and paste it into a
sheet within workbook1. Then workbook2 closes.
Everything all fine and good until something needs added
to workbook2. Workaround is closing workbook1 and reopen
to refresh the data.

I want to add an option to refresh without closing it.
Below is a snippet of the code (which doesnt work). I am
trying to get NumRows variable to work, but having
problems getting the value of NumRows to pass.

Private Sub Workbook_Open()

Dim NumRows As Long
Dim sh1 As Worksheet 'Sheet1!Contracts.xls
Dim sh2 As Worksheet 'Contracts!Settlement4b.xls
Dim rng1 As String
Dim i, j As Integer

'Refresh data of Contracts worksheet in
C:\CCF\Settlement4.xls from data contained
'in worksheet Sheet1 in C:\CCF\Contracts1.xls
Application.StatusBar = "Loading Contract File..."

Workbooks.Open Filename:="C:\CCF\Contracts1.xls"
Set sh1 = Workbooks("Contracts1.xls").Worksheets
("Sheet1")
Set sh2 = Workbooks("Copy of
Settlement4b.xls").Worksheets("Contracts")
'Determine number of rows in C:\CCF\Contracts1.xls
Sheet1

'numRows = Application.CountA(sh1.Range("A:A"))
'CountRows

'Copy from C:\CCF\Contracts1.xls!Sheet1 and
'Paste in C:\CCF\Settlement4.xls!Contracts
sh1.Range("A1:AJ" & NumRows).Copy sh2.Range("A1")

'Create a string variable to be used later in code
rng1 = ("A1:AJ" & NumRows)

Some more code
End sub

In Module1:

Option Explicit
Global NumRows As Long


Function CountRows(ByVal NumRows As Long)

Dim sht1 As Object
Set sht1 = Worksheets("Sheet1")

NumRows = Application.CountA(sht1.Range("A:A"))
End Function


 
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
VBA - passing Variables to subroutines Madduck Excel Discussion (Misc queries) 12 September 19th 08 03:20 AM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing Variables Tom Ogilvy Excel Programming 0 July 23rd 04 04:19 PM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM


All times are GMT +1. The time now is 08:03 AM.

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"