I'm new to this forum. I have a Workbook named Call Tracker which is a macro-enabled file with a userform in it. I also have another Workbook named Call Spreadsheet which is to contain the data captured from the userform. On the userform there's a SAVE button which should be opening the Call Spreadsheet file, going to the bottom row, and storing the information. My subroutine is in its infancy at this point, so I'm trying to test a number of things. I tried using the LastRow routine i found on the Internet, but it doesn't seem to be giving me the correct answer (although it might be that it's looking in the wrong place). So I wrote my own FOR ... NEXT loop to go through the Call Spreadsheet to identify the first non-blank row, but that's not working properly either.
Below is a sample of what my Call Spreadsheet looks like (Sheet1)
Below is what the Call Tracker spreadsheet looks like (Sheet1).
Following is the guilty routine....
Both MSGBOXes "ActiveWorkbook.Name" show the correct workbook name.
The MSGBOX "LastRow" is commented out.
The MSGBOXes ".Cells(i, 1)" and "NewRow" show values that correspond to the Call Tracking spreadsheet instead of the Call Spreadsheet itself.
The MSGBOX [a1] is showing a value correctly corresponding to the Call Spreadsheet file (i.e., WSS STDID).
I'm getting mixed results and I'm not sure why....
If someone could assist, that would be awesome!
Below is a sample of what my Call Spreadsheet looks like (Sheet1)
Below is what the Call Tracker spreadsheet looks like (Sheet1).
Following is the guilty routine....
Code:
Private Sub CommandButton1_Click()
Dim wb1, wb2 As Workbook
Dim ws1, ws2 As Worksheet
Dim cb1, cb2, cb3, cb4 As String
Dim NewRow, LastRow, i As Long
Set wb1 = ThisWorkbook 'Store currently active workbook name.
Set ws1 = wb1.Worksheets("Sheet1")
cb1 = Me.ComboBox1.Value: cb2 = Me.ComboBox2.Value: cb3 = Me.ComboBox3.Value: cb4 = Me.ComboBox4.Value 'Capture information selected.
MsgBox ActiveWorkbook.Name
'Reset ComboBox values.
Me.ComboBox1.ListIndex = 1 'Set default value back to "No".
Me.ComboBox2.ListIndex = 1 'Set default value back to "Customer".
Me.ComboBox3.ListIndex = -1 'Set default value back to blank entry.
Me.ComboBox4.ListIndex = -1 'Set default value back to blank entry.
Me.ComboBox4.Visible = False
'If cb4 = "" Then
'End If
Workbooks.Open "H:\Call Tracking\Call Spreadsheet.xlsx"
Set wb2 = ThisWorkbook
Set ws2 = wb2.Worksheets("Sheet1")
MsgBox ActiveWorkbook.Name
With ws2
' LastRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row
'MsgBox LastRow
For i = 1 To 10000
If Not IsEmpty(.Cells(i, 1)) Then 'If the cell isn't empty...
i = i + 1
MsgBox .Cells(i, 1)
Else
NewRow = i
Exit For
End If
Next
MsgBox NewRow
MsgBox [a1]
End With
'MsgBox ComboBox1.Value & vbCrLf & ComboBox2.Value & vbCrLf & ComboBox3.Value
'MsgBox Environ$("USERNAME") & vbCrLf & Date$ & vbCrLf & Time$
End Sub
Both MSGBOXes "ActiveWorkbook.Name" show the correct workbook name.
The MSGBOX "LastRow" is commented out.
The MSGBOXes ".Cells(i, 1)" and "NewRow" show values that correspond to the Call Tracking spreadsheet instead of the Call Spreadsheet itself.
The MSGBOX [a1] is showing a value correctly corresponding to the Call Spreadsheet file (i.e., WSS STDID).
I'm getting mixed results and I'm not sure why....
If someone could assist, that would be awesome!