Well that might be part of the problem, there is not a value in that cell. I am entereing in values into the rows from a userform. So there is no value in the order Number field to start with. This is what I was trying to get done in code. I did add the sheet name to your code and I am still getting the same error. I also tried adding DHORD into the cell and it also errored out. Code below
Private Sub Tset()
Dim RandomString As String, rgch As String
Dim Count As Long
Randomize
If Not Sheet1.Range("A1") = "" Then
Count = Right(Sheet1.Range("A1"), 5)
Count = Count + 1
Else
Count = 1
End If
rgch = "abcdefghijklmnopqrstuvwxyz"
rgch = rgch & UCase(rgch) & "0123456789"
Dim i As Long
For i = 1 To 5
RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1)
Next
Sheet1.Range("A1").Value = RandomString & Format$(Count, "00000")
End Sub
My Save Code - doing some other testing as well, so the call to this proc is commented out at the time
Private Sub Save_Click()
lastrow = Range("C" & Rows.Count).End(xlUp).Row
Range("A" & lastrow + 1).Value = "DH" + "0"
Range("B" & lastrow + 1).Value = TTNum.Text
Range("C" & lastrow + 1).Value = Req.Text
Range("D" & lastrow + 1).Value = ReqD.Text
Range("F" & lastrow + 1).Value = DH.Text
Range("G" & lastrow + 1).Value = DHNum.Text
Range("H" & lastrow + 1).Value = DHCst.Text
Range("R" & lastrow + 1).Value = Rsn.Text
'Tset
MsgBox "One record written to Sheet1"
response = MsgBox("Do you want to enter another record?", _
vbYesNo)
If response = vbYes Then
DH.Value = ""
DHNum.Value = ""
DHCst.Value = ""
Rsn.Value = ""
VnNum.Value = ""
VnCst.Value = ""
VnAd.Value = ""
VnPh.Value = ""
VnWb.Value = ""
VnCt.Value = ""
Vn.Value = ""
VnZip.Value = ""
st.Value = ""
VnRsn.Value = ""
Req.Value = ""
ReqD.Value = ""
TT.Value = ""
TTNum.Value = ""
TT.SetFocus
Else
Unload Me
End If
End Sub
Bookmarks