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: 573
Default variable not transferring?

With a lot of help here, I've written some code to compare 2
spreadsheets. But when I couple the code to run a userform to get the
filenames to compare with the code to align the data in corresponding
rows, the second macro doesn't recognize the workbook names that have
been saved in the first macro.

Here's the code with the userform:

Option Explicit
Public wsNew As Worksheet
Public wsOrig As Worksheet
Public wbNew As Workbook
Public wbOrig As Workbook


Private Sub CancelButton_Click()
Unload UserForm2
End Sub

Private Sub OkButton_Click()
'Workbooks(ComboBox1.Text).Select
Set wbNew = Workbooks(ComboBox1.Text)
Set wbOrig = Workbooks(ComboBox2.Text)
'wbNew.Activate
UserForm2.Hide
Call EvenOutRows

End Sub

Private Sub UserForm_Initialize()
Dim wbk As Workbook
For Each wbk In Workbooks
ComboBox1.AddItem wbk.Name
ComboBox2.AddItem wbk.Name
Next wbk

End Sub

And the other code:

Sub EvenOutRows()

Dim wsNew As Worksheet
Dim wsOrig As Worksheet
Dim lCurRow As Long
Dim lrowNew As Long
Dim lrowOrig As Long
UserForm2.Show

Set wsOrig = wbOrig.Worksheets("Sheet1") <-------OBJECT VARIABLE OR
WITHBLOCK VARIABLE NOT SET

Set wsNew = wbNew.Worksheets("sheet1")

lCurRow = 2
Do While Not IsEmpty(wsNew.Cells(lCurRow, 1)) And _
Not IsEmpty(wsOrig.Cells(lCurRow, 1))
If wsNew.Cells(lCurRow, 1) wsOrig.Cells(lCurRow, 1) Then
wsNew.Rows(lCurRow).Insert: lCurRow = lCurRow + 1
ElseIf wsOrig.Cells(lCurRow, 1) wsNew.Cells(lCurRow, 1) Then
wsOrig.Rows(lCurRow).Insert: lCurRow = lCurRow + 1
ElseIf wsNew.Cells(lCurRow, 1) = wsOrig.Cells(lCurRow, 1) Then
lCurRow = lCurRow + 1
End If
Loop
Application.Run "Compare.xla!Compare"
End Sub

The variables have been declared publicly in both modules. Any
suggestions?

 
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
Transferring like data npignetti Excel Discussion (Misc queries) 4 October 21st 08 04:06 AM
Transferring Data MJ Excel Worksheet Functions 1 April 16th 08 06:49 PM
Transferring Data KandK Excel Discussion (Misc queries) 0 April 24th 06 10:25 AM
Transferring rows with variable criteria chris100[_32_] Excel Programming 1 October 17th 05 01:03 PM
transferring code from VBA to a VB dll PM Excel Programming 4 November 5th 04 02:20 PM


All times are GMT +1. The time now is 08:38 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"