Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Transferring like data | Excel Discussion (Misc queries) | |||
Transferring Data | Excel Worksheet Functions | |||
Transferring Data | Excel Discussion (Misc queries) | |||
Transferring rows with variable criteria | Excel Programming | |||
transferring code from VBA to a VB dll | Excel Programming |