davedave24
Programmer
Hello! My procedure writes the data to a sheet, from rows B-V. It writes the data from B-V, then repeats it 5 times down to cell AU. It doesn't write the 20 pieces of data exactly though (B-V writes normally); starting at W, it writes what went in column D; X will contain what went in column E, and so on, as shown below:
D - E - F - G - H - blank - I - blank - K - J - no idea - no idea - repeat another 4 times
The two "no idea" - it puts 2 values in that I don't know where from - I didn't enter them into my form, and they aren't from any of the normal columns (B-V), in fact, they are nowhere on the sheet.
I don't believe it's the code that actually *writes* the data to the sheet, as that is used to write to an identical sheet in another workbook and it works fine.
Here's my code:
I have 2 worksheets, called 'skipleft', and 'skipright'. The user selects one from a combobox. When they hit the ENTER button, it calls EnterSkipData, then SkipDataWorkbook.
edit: I've been playing around with this. If I don't call the SkipData procedure, and just write textDate in on it's own in the first cell, it puts all the other values from the userform into the other colums without being told to (in the wrong places). What is causing this? It's driving me mad!
I've also changed the SkipLR variable to make it just write to the skipleft worksheet, but it does the same
First, this writes to the skipleft or skipright worksheet. The variable SkipLR is determined from a combobox and chooses which sheet.
This is the procedure that just writes the data. AddBorders is a public sub in a module that just adds a border to the cell. I use this method to write data to several other sheets without any issue. SkipDataWorkbook is another procedure that opens a workbook with the exact same layout as the skipleft/skipright sheet, and writes the data there. That one works fine.
This is the SkipDataWorkbook, which opens a workbook (with the same layout as the sheet), and writes the data with no issue, in case someone asks for it.
This explains the variable SkipLR, used to determine if the user selects left or right skip. This doesn't appear to be the issue.
And this is where the skip combobox is filled on userform_initialize. It's simply getting the name of the skip from cell B2 on the skipleft or skip right worksheet.
This is a crosspost on ozgrid forums
Thanks for any help
D - E - F - G - H - blank - I - blank - K - J - no idea - no idea - repeat another 4 times
The two "no idea" - it puts 2 values in that I don't know where from - I didn't enter them into my form, and they aren't from any of the normal columns (B-V), in fact, they are nowhere on the sheet.
I don't believe it's the code that actually *writes* the data to the sheet, as that is used to write to an identical sheet in another workbook and it works fine.
Here's my code:
I have 2 worksheets, called 'skipleft', and 'skipright'. The user selects one from a combobox. When they hit the ENTER button, it calls EnterSkipData, then SkipDataWorkbook.
edit: I've been playing around with this. If I don't call the SkipData procedure, and just write textDate in on it's own in the first cell, it puts all the other values from the userform into the other colums without being told to (in the wrong places). What is causing this? It's driving me mad!
I've also changed the SkipLR variable to make it just write to the skipleft worksheet, but it does the same
First, this writes to the skipleft or skipright worksheet. The variable SkipLR is determined from a combobox and chooses which sheet.
Code:
Sub EnterSkipData()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WRITE THE DATA TO THE SKIPLEFT/SKIPRIGHT WORKSHEET
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error GoTo ErrHandler:
ErrHandler:
SkipMsg = "There was a problem writing the data to the Skip (left/right) worksheet in the All Deliveries 2010 workbook. This shouldn't have happened!" & vbCrLf & vbCrLf
Resume Next
'Windows("All Deliveries 2010").Activate 'enter the data in skipleft/right
With Workbooks("All Deliveries 2010").Sheets(SkipLR) 'select the skipleft/skipright sheet depending on the variable determined by comboskip_change()
.Select
.Cells(Rows.Count, 2).End(xlUp).Select 'find the last row in B
ActiveCell.Offset(1, 0).Select 'move down 1 row
SkipData 'procedure that enters the data
SkipMsg = "" 'all went well, no need for an error message at the end
End With
End Sub
This is the procedure that just writes the data. AddBorders is a public sub in a module that just adds a border to the cell. I use this method to write data to several other sheets without any issue. SkipDataWorkbook is another procedure that opens a workbook with the exact same layout as the skipleft/skipright sheet, and writes the data there. That one works fine.
Code:
Sub SkipData()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' THIS WRITES THE DATA INTO THE SKIP WORKSHEETS. CALLED BY EnterSkipData AND SkipDataWorkbook
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ActiveCell = textDate.Text
AddBorders 'adds a border to the cell
ActiveCell.Offset(0, 1).Select
ActiveCell = comboCustomer.Text
AddBorders
ActiveCell.Offset(0, 1).Select
ActiveCell = textConsignmentNote
AddBorders
'etc. 20 pieces of data, I won't list it all but it's the same as above
'insert a new row
ActiveCell.Offset(1).EntireRow.Insert
This is the SkipDataWorkbook, which opens a workbook (with the same layout as the sheet), and writes the data with no issue, in case someone asks for it.
Code:
Sub SkipDataWorkbook()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WRITES THE DATA TO THE SKIP DATA WORKBOOK. THIS IS CALLED BY EnterSkipData()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Dim SkipWorkbook As Workbook
Dim p As String
p = "C:\Users\Dave\Documents\xl\SKIP DATA " 'file path of the SKIP DATA workbook
If FileThere(p & SkipNumber & ".xlsx") Then 'check if the file exists, open it
Set SkipWorkbook = Workbooks.Open(p & SkipNumber) 'SKIP DATA workbook
With SkipWorkbook.Worksheets("Sheet1")
.Cells(Rows.Count, 2).End(xlUp).Select 'find last row in column B
ActiveCell.Offset(1, 0).Select 'move down 1 row
SkipData 'procedure that enters the data
End With
SkipWorkbook.Save 'save
SkipWorkbook.Close 'close
SkipDataMsg = "" 'all went well, no need for an error message at the end
Else 'the workbook could not be found. This should not happen as the workbook is created when a new skip is created
SkipDataMsg = "There was a problem writing the data to the SKIP DATA workbook. The SKIP DATA " & SkipNumber & " file doesn't exist. You must manually create the skip file now and enter the data." _
& vbCrLf & vbCrLf
End If
End Sub
This explains the variable SkipLR, used to determine if the user selects left or right skip. This doesn't appear to be the issue.
Code:
Private Sub comboSkip_Change()
'cut off the words to leave only the skip name
Select Case comboSkip.ListIndex
Case 0: SkipNumber = Mid(comboSkip, 12) 'left skip
SkipLR = "skipleft"
Case 1: SkipNumber = Mid(comboSkip, 13) 'right skip
SkipLR = "skipright"
End Select
End Sub
And this is where the skip combobox is filled on userform_initialize. It's simply getting the name of the skip from cell B2 on the skipleft or skip right worksheet.
Code:
comboSkip.AddItem "Left skip" & vbTab & Mid(Workbooks("All Deliveries 2010").Sheets("skipleft").Range("B2").Value, 5)
comboSkip.AddItem "Right skip" & vbTab & Mid(Workbooks("All Deliveries 2010").Sheets("skipright").Range("B2").Value, 5)
comboSkip.ListIndex = 0
This is a crosspost on ozgrid forums
Thanks for any help