How to appear in the right column? - excel

I have a problem which is the data did not appear in the column. Only the first data. Name data should appear at column B9.
And fyi, name will appear at column A in last data.
The data will come out like this;
Where should I need to fix my error?
And the error I think is at this line -
ws.Cells(totalRows + 1, 1) = txtName.Text
Hope anyone of you can help me.
Thank you in advance.
Private Sub cmdAdd_Click()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Master Data")
Dim Addme As Range, str As String, totalRows As Long
Set Addme = ws.Cells(ws.Rows.Count, 3).End(xlUp).Offset(1, 0)
Application.ScreenUpdating = False
If Me.txtName = "" Or Me.cboAmount = "" Or Me.cboCeti = "" Then
MsgBox "There is insufficient data, Please return and add the needed information"
Exit Sub
End If
totalRows = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
totalRows = Application.WorksheetFunction.Max(totalRows, 3)
ws.Cells(totalRows + 1, 1) = txtName.Text
If cbWhatsapp.Value = True Then
str = "Whatsapp, "
End If
If cbSMS.Value = True Then
str = str & "SMS, "
End If
If cbEmail.Value = True Then
str = str & "Email, "
End If
If cbFacebook.Value = True Then
str = str & "Facebook, "
End If
If cbPhoneCall.Value = True Then
str = str & "Phone Call, "
End If
str = Left(str, Len(str) - 2)
ws.Cells(totalRows + 1, 2) = str
If optYes.Value = True Then
ws.Cells(totalRows + 1, 3) = "Yes"
ElseIf optNo.Value = True Then
ws.Cells(totalRows + 1, 3) = "No"
End If
ws.Cells(totalRows + 1, 4) = cboAmount.Value
ws.Cells(totalRows + 1, 5) = cboCeti.Value
ws.Cells(totalRows + 1, 6) = txtPhone.Text
ws.Cells(totalRows + 1, 7) = txtEmail.Text
ws.Range("B9:H10000").Sort Key1:=Range("F9"), Order1:=xlAscending, Header:=xlGuess
MsgBox "Your data was successfully added"
Sheet1.Select
On Error GoTo 0
Exit Sub
End Sub

Related

How to compare two values in VBA when a value is bound to vbNewLine in Excel or Access

This is about the structure of a calendar and since I already have too many functions built in, I am not allowed to change the block with vbNewLine , so I need to find a way to solve the problem at this one point:
A function should compare two values and trigger an action in case of a match.
The value myArray(i, 2) ist the Day-Number:
Private Sub InitVariables()
intMonth = Me.cboMonth
intYear = Me.cboYear
lngFirstDayOfMonth = CLng(DateSerial(intYear, intMonth, 1))
intFirstWeekday = getFirstWeekday(lngFirstDayOfMonth)
intDaysInMonth = getDaysInMonth(intMonth, intYear)
End Sub
Private Sub InitArray()
Dim i As Integer
ReDim myArray(0 To 41, 0 To 2)
For i = 0 To 41
myArray(i, 0) = lngFirstDayOfMonth - intFirstWeekday + 1 + i
If Month(myArray(i, 0)) = intMonth Then
myArray(i, 1) = True
myArray(i, 2) = Day(myArray(i, 0))
Else
myArray(i, 1) = False
End If
Next i
End Sub
Private Sub LoadArray()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsFiltered As DAO.Recordset
Dim strsql As String
Dim i As Integer
Dim OrgTime As Date
Dim MyStrTime As String
On Error Resume Next
strsql = "SELECT * from qrytblImVst;"
Set db = CurrentDb
Set rs = db.OpenRecordset(strsql)
If Not rs.BOF And Not rs.EOF Then
For i = LBound(myArray) To UBound(myArray)
If myArray(i, 1) Then
rs.Filter = "[vDate]=" & myArray(i, 0)
Set rsFiltered = rs.OpenRecordset
Do While (Not rsFiltered.EOF)
OrgTime = rsFiltered!vZeit
MyStrTime = Format(OrgTime, "hh:mm")
myArray(i, 2) = myArray(i, 2) & vbNewLine _
& "<div><font color=red> " + MyStrTime + " </div>"
End If
rsFiltered.MoveNext
Loop
End If
Next i
End If
rsFiltered.Close
rs.Close
Set rsFiltered = Nothing
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub PrintArray()
'On Error Resume Next
Dim strCtlName As Variant
Dim strCtlName1 As Variant
Dim i As Integer
Dim lngBlack As Long
Dim lngWhite As Long
lngBlack = RGB(36, 39, 50)
lngWhite = RGB(166, 166, 166)
For i = LBound(myArray) To UBound(myArray)
strCtlName = "TXT" & CStr(i + 1)
Controls(strCtlName).Tag = i
Controls(strCtlName) = ""
Controls(strCtlName) = myArray(i, 2)
If IsNull(Controls(strCtlName)) Then
Controls(strCtlName).Visible = False
Else
Controls(strCtlName).Visible = True
End If
If CStr(Me.cboMonth) = CStr(Month(Date)) And CStr(Me.cboYear) = CStr(Year(Date)) And Len(myArray(i, 2)) <> 0 Then
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
Else
Controls(strCtlName).BorderColor = lngWhite
Controls(strCtlName).BorderWidth = 1
End If
strCtlName = "CAL" & CStr(i + 1)
Controls(strCtlName).Tag = i
Controls(strCtlName) = ""
If InStr(myArray(i, 2), "div") Then
Controls(strCtlName) = Left(myArray(i, 2), 2)
Else
Controls(strCtlName) = myArray(i, 2)
End If
If IsNull(Controls(strCtlName)) Then
Controls(strCtlName).Visible = False
Else
Controls(strCtlName).Visible = True
End If
Next i
End Sub
This is how the comparison looks:
If Left(myArray(i, 2), 2) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
I always get a FALSE as a result because vbNewLine changes the day number value in such a way that there is no match.
To check what is causing the problem I added "//" and it looks like this
msgbox Left(myArray(i, 2), 2) & "//"
The result is:
5
//
How can I solve this problem, for all calendar days? Thanks!
Your comparison is looking at the first two characters of the stored value. When the day number is less than 10, the second character will be vbNewLine because the day number is only one digit.
Instead of using Left to capture a fixed number of characters, you can use Split to capture everything to the left of vbNewLine.
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
Split will return Error (9) when myArray(i,2) doesn't have a value. You'll need to introduce a check for that case:
If Len(myArray(i,2)) <> 0 Then
If Split(myArray(i, 2), vbNewLine)(0) = CStr(Day(Date)) Then
Controls(strCtlName).BorderColor = lngRed
Controls(strCtlName).BorderWidth = 2
End If
End If

I have an error of range using Useform "Method_Default of object range failed

I am creating an useform to create, modify, search and delete data.
when I'm running the code to create data, it shows the error:
Run-time error '-2147417848(80010108)':
Method'_Default' of object 'range'failed.
I have tried to change the object (name of te worksheet.) for (activesheet.) activating the sheet where I am registering the data I want to add but still not working.
The code has several procedures, but I'm having trouble just when I am creating new data
At the beginning it worked well but now it has this issue. I am new programming.
The code fails in this area
S
et oCelda = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1)
oCelda = consecutivo
complete code as follow
Private Sub Cmb_Registro_Click()
Dim oCelda As Range
Dim bCheck As Boolean
Dim Consecutivo as Double, file As long, Col As long, Final As Long
Worksheets("Data").Activate
bCheck = Txt_Fecha <> "" And Cbo_Categoria <> "" And Cbo_Subcategoria <> "" And Txt_Monto <> "" _
And Cbo_Periodo <> "" And Txt_Descripcion <> ""
Col = 1
fila = 2
Cbo_Periodo.Enabled = False
Do While ActiveSheet.Cells(fila, Col) <> Empty
fila = fila + 1
Loop
Final = fila
Consecutivo = Val(ActiveSheet.Cells(Final - 1, Col))
If Consecutivo = 0 Then
consecutivo = 1
Else
consecutivo = ActiveSheet.Cells(Final - 1, Col) + 1
End If
If bCheck And optIngreso Then
*Set oCelda = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1)
oCelda = consecutivo*
oCelda.Offset(0, 1) = CDate(Txt_Fecha)
oCelda.Offset(0, 2) = CLng(Txt_Monto)
oCelda.Offset(0, 3) = lblIngreso.Caption
oCelda.Offset(0, 4) = Txt_Descripcion
oCelda.Offset(0, 5) = Cbo_Categoria
oCelda.Offset(0, 6) = Cbo_Subcategoria
oCelda.Offset(0, 7) = Cbo_Periodo
MsgBox "Registro completo"
Unload Me
ElseIf bCheck And optEgreso Then
*Set oCelda = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1)
oCelda = consecutivo*
oCelda.Offset(0, 1) = CDate(Txt_Fecha)
oCelda.Offset(0, 2) = CLng(Txt_Monto)
oCelda.Offset(0, 3) = lblEgreso.Caption
oCelda.Offset(0, 4) = Txt_Descripcion
oCelda.Offset(0, 5) = Cbo_Categoria
oCelda.Offset(0, 6) = Cbo_Subcategoria
oCelda.Offset(0, 7) = Cbo_Periodo
MsgBox "Registro completo"
Unload Me
Else
MsgBox "Faltan datos"
End If
Worksheets("Inicio").Activate
End Sub

Creating a loop within a UserForm

this is a continuation of my previous question...
I'm trying to create a user form that will go through a list on a worksheet (TESTER). The form should display the first row of data from the list. User will also be able to select one of two options Active or ITW. Finally, the user is free to add additional comments.
This is where I'm running into trouble, once the user clicks Add, the values from the form should populate the next blank row in a separate sheet (pasteHere). I have no issues with the form displaying the next line of data on the list, but I don't know how to create a loop that will allow me to find the next blank row after clicking the add button. At the moment, I've only initialized j as 1. And every time I click add, it will paste on the first row in the pasteHere worksheet.
Sub addBtn_Click()
Application.ScreenUpdating = False
Dim pasteSheet As Worksheet
Dim j As Long
j = 1 'how can I loop this part
Set pasteSheet = Application.Worksheets("pasteHere")
pasteSheet.Cells(j, j) = ric
pasteSheet.Cells(j, j + 2) = name
pasteSheet.Cells(j, j + 4) = valueUSD
pasteSheet.Cells(j + 1, j) = dstr
i = i + 1
j = j + 2
UserForm1_Initialize
End Sub
Would appreciate any help here. Full code below:
Public valueUSD, name, ric, dstr, sitchStr, pStr As String
Public i, lRow As Long
Sub UserForm1_Initialize()
If Worksheets("pasteHere").Range("A1") = "" Then
i = 2
End If
activeCheck.Value = False
itwCheck.Value = False
TextBox2.Value = ""
ric = Worksheets("Tester").Range("H" & i)
name = Worksheets("Tester").Range("B" & i)
valueUSD = Worksheets("Tester").Range("C" & i)
sitchStr = ""
dstr = ""
pStr = ric & " " & name & " " & valueUSD & " "
UserForm1.Label1.Caption = pStr
End Sub
Sub activeCheck_Change()
If activeCheck.Value = True Then
sitchStr = sitchStr + activeCheck.Caption
Else
sitchStr = ""
End If
End Sub
Sub itwCheck_Change()
If activeCheck.Value = False And itwCheck.Value = True Then
sitchStr = sitchStr + itwCheck.Caption
ElseIf activeCheck.Value = True And itwCheck.Value = True Then
MsgBox ("You can only be active OR ITW")
End If
End Sub
Sub TextBox2_Change()
dstr = sitchStr & ", " & TextBox2.Value
End Sub
Sub addBtn_Click()
Application.ScreenUpdating = False
Dim pasteSheet As Worksheet
Dim j As Long
j = 1 'how can I loop this part
Set pasteSheet = Application.Worksheets("pasteHere")
pasteSheet.Cells(j, j) = ric
pasteSheet.Cells(j, j + 2) = name
pasteSheet.Cells(j, j + 4) = valueUSD
pasteSheet.Cells(j + 1, j) = dstr
i = i + 1
j = j + 2
UserForm1_Initialize
End Sub
Sub skipBtn_Click()
i = i + 1
UserForm1_Initialize
End Sub
Sub exitBtn_Click()
Unload Me
End Sub

Unload form after printing in Excel

In frmClothingPricer, when cmdPrint is pressed, frmPrint activates and is printed however many times asked for. I don't want 10+ frmPrint "active". How can I close frmPrint after each print loop? I have tried it on frmPrint "Unload Me" but that doesn't unload it either. ?? what am I missing?
Routine for printing
If Len(HowMany) = 0 Then
End
Else
Do Until i = HowMany
frmPrint.Show 'prints form on activation
i = i + 1
Unload frmPrint 'this isn't working = several forms are open
Loop
End If
frmPrint code
Private Sub UserForm_Initialize()
PrintMe
End Sub
Private Sub PrintMe()
lblPrintMonthCode.Caption = frmClothingPricer.MonthCode
lblPrintPricer.Caption = frmClothingPricer.Pricer
lblPrintCost.Caption = (frmClothingPricer.Cost * 100)
lblPrintDescription.Caption = frmClothingPricer.Description
lblPrintPrice.Caption = frmClothingPricer.Price
lblPrintItemNumber = frmClothingPricer.ItemNumber
frmPrint.PrintForm
'tried unload.me here with same results
End Sub
I solved it by keeping all the code except labels on the original form. The latest errors revolved around variables I messed up switching around. It now works perfectly (below):
form1
Public Price As Double
Public Percent As Double
Public Cost As Currency
Public Description As String
Public MonthCode As Integer
Public Pricer As String
Public ItemNumber As Double
Private Sub UserForm_Initialize()
Pricer = InputBox("Enter Your Pricer Number", vbOKOnly, "")
If Len(Pricer) = 0 Then 'Checking if Length of name is 0 characters
End
Else
End If
End Sub
Private Sub cmdSearch_Click()
Dim Response As Long
Dim NotFound As Integer
Dim arr As Variant
Dim i As Long
Dim str1 As String, str2 As String, str3 As String
lbxCost.BackColor = &H80000005
lbxCost.Locked = False
NotFound = 0
ActiveWorkbook.Sheets("Items").Activate
Response = Val("0" & Replace(txtItemNumber.Text, "-", ""))
ItemNumber = Response
If Response <> False Then
With ActiveSheet
arr = .Range("A2:D" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
For i = 1 To UBound(arr)
If arr(i, 1) = Response Then
str1 = IIf(str1 = "", arr(i, 2), str1 & "|" & arr(i, 2))
str2 = IIf(str2 = "", arr(i, 3), str2 & "|" & arr(i, 3))
str3 = IIf(str3 = "", arr(i, 4), str3 & "|" & arr(i, 4))
End If
Next
If str1 = "" Then
MsgBox "Item Number Not Found!", vbExclamation
NotFound = 1
txtItemNumber.Text = ""
txtItemNumber.SetFocus
Else
Frame1.Visible = True
lbxDescription.List = Split(str1, "|")
lbxCost.List = Split(str2, "|")
ListBox3.List = Split(str3, "|")
End If
End If
lbxCost.ListIndex = 0
End Sub
Private Sub lbxCost_Click()
Frame2.Visible = True
End Sub
Private Sub lbxPercent_Click()
Frame3.Visible = True
lbxCost.BackColor = &H80000004
lbxCost.Locked = True
For x = 0 To lbxCost.ListCount - 1
If lbxCost.Selected(x) = True Then
Cost = lbxCost.List(x)
Description = lbxDescription.List(x)
End If
Next x
For y = 0 To lbxPercent.ListCount - 1
If lbxPercent.Selected(y) = True Then
Percent = lbxPercent.List(y)
End If
Next y
lblPrice.Caption = (Round(Cost * (1 + (Percent / 100)), 0)) - 0.01
Price = lblPrice.Caption
lblItemNumber.Caption = txtItemNumber.Text
lblDescription.Caption = Description
MonthCode = (Year(Now)) + (Month(Now)) - 1765
lblMonthCode.Caption = MonthCode
lblPricer.Caption = Pricer
cmdPrint.SetFocus
End Sub
Private Sub cmdPrint_Click()
Dim i As Integer
Dim Howmany As Double
Load frmPopup
Howmany = Val(txtQuantity.Text)
i = 1
Do Until i > Howmany
frmPopup.PrintForm
i = i + 1
Loop
lbxPercent.ListIndex = -1
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
txtItemNumber.Text = ""
txtItemNumber.SetFocus
Unload frmPopup
End Sub
form2
Private Sub UserForm_Initialize()
lblPrintMonthCode.Caption = frmClothingPricer.MonthCode
lblPrintPricer.Caption = frmClothingPricer.Pricer
lblPrintCost.Caption = (frmClothingPricer.Cost * 100)
lblPrintDescription.Caption = frmClothingPricer.Description
lblPrintPrice.Caption = frmClothingPricer.Price
lblPrintItemNumber = frmClothingPricer.ItemNumber
End Sub

unable to load data into different tabs in Excel 2013 using VB6

In my organization we have one old project/application which was build on Visual Basic 6.0
In that application we have export to Excel "button" where data gets populated into different tabs in spreadsheet with click. It was working very well with Excel 2010 and later until we moved to EXCEL 2013.
Issue: We need data to get exported into 2 tabs in excel 2013 whereas its coming in 1 tab only. I tried using package and deployment wizard and all possible help available. So far no luck. Please let me know if you have any questions or if I am not enough clear. Please find below my code.
Dim uprev As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim ExcelWasNotRunning As Boolean ' Flag for final release.
Dim n As Integer
Dim n1 As Integer
Dim n2 As Integer
Dim i As Integer
Dim lastrevdate As String
Dim lastrevrow As Integer
Dim lastrow As Integer
Dim previouspcno As Integer
Dim xlcol As String
Dim j As Integer
Dim k As Integer
Dim dc As Adodc
Dim mrc As Recordset
Dim qpa As New QPArray
Dim Found As Long
Dim StartInd As Long
Dim bFound As Boolean
Dim crlf As String
On Error GoTo errorhandler1
crlf = Chr(13) & Chr(10)
ReDim qs(10) As String
ReDim q(10) As Integer
ReDim hdr(15) As Integer
ReDim rev(10, 0) As String
ReDim part(0) As String
ReDim sl(nof) As String
ReDim cmpsql2(0) As String
ReDim deletedfromsql(3, 0) As String
Dim doThis As Integer
Dim iReturn As Integer
Dim revlev As String
Dim Date_Engr As String
Dim Date_Checker As String
'On Error Resume Next ' Defer error trapping.
'Removed, not checking to see if excel is open properly
'Bert - 6/5/07
'Set xlApp = GetObject(, "Excel.Application")
'If Err.Number <> 0 Then
' ExcelWasNotRunning = True
'Else
' MsgBox ("Please Close Excel before continuing")
' Exit Sub
'End If
Err.Clear ' Clear Err object in case error occurred.
iReturn = MsgBox("Please Close ALL Excel applications before continuing", vbOKOnly, "WARNING")
ExcelWasNotRunning = True
'fixwidth
Screen.MousePointer = vbHourglass
'DetectExcel
Set xlApp = Excel.Application
'path(8) = "C:\SwitchGear\Files1\eng_prod\Jobs\cs01157\medt\"
If Dir(Defaults.medt & "\" & cs & sos & "mbom.xls", vbNormal) <> "" Then
mbomflag = 1
FileCopy Defaults.medt & "\" & cs & sos & "mbom.xls", Defaults.medt & "\" & cs & sos & "mbom.bak"
Set xlBook = GetObject(Defaults.medt & "\" & cs & sos & "mbom.xls")
Set xlSheet = xlBook.Worksheets(1)
Set xlsheet2 = xlBook.Worksheets(2)
Do
qs(1) = "1. Do not list changes on rev sheet" & crlf
qs(1) = qs(1) & "2. list changes on rev sheet but do not increase rev level" & crlf
qs(1) = qs(1) & "3. list changes on rev sheet and increase rev level"
qs(0) = InputBox(qs(1))
If qs(0) = "" Then Exit Sub
Loop Until qs(0) > "0" And qs(0) < "4"
If qs(0) = "3" Then ' up the revision
uprev = 2
revlev = xlsheet2.Cells(5, 3) + 1
Date_Engr = Date
Date_Checker = Date
Else
uprev = 1
revlev = xlsheet2.Cells(5, 3)
Date_Engr = xlSheet.Cells(16, 2) ' get the old rev number
Date_Checker = xlSheet.Cells(16, 3)
End If
lastrow = xlSheet.Cells.Range("E20").End(xlDown).Row
ReDim cmpxl2(0) As String
ReDim cmpxl3(0) As String
ReDim cmpxl4(0) As String
n = 0
For i = 20 To lastrow
If xlSheet.Cells(i, 2) <> "" Then
n = n + 1
ReDim Preserve cmpxl2(n) As String
ReDim Preserve cmpxl3(n) As String
ReDim Preserve cmpxl4(n) As String
cmpxl2(n) = xlSheet.Cells(i, 2) & " " & Format(i)
cmpxl3(n) = xlSheet.Cells(i, 3)
cmpxl4(n) = xlSheet.Cells(i, 4)
End If
Next i
n1records = Adodc1.Recordset.RecordCount
'If n > n1records Then 'it's been deleted from sql so find the part and add to xl revision sheet
n1 = 0
ReDim cmpsql2(n1records) As String
With Adodc1.Recordset
For i = 1 To n1records
If i = 1 Then
Adodc1.Recordset.MoveFirst
Else
Adodc1.Recordset.MoveNext
End If
cmpsql2(i) = !pcno
Next i
End With
For i = 1 To n
bFound = qpa.Find(cmpsql2(), Left$(cmpxl2(i), 4), Found, , 1)
If bFound = False Then
q(1) = Val(Mid$(cmpxl2(i), 6))
n1 = n1 + 1
ReDim Preserve deletedfromsql(3, n1)
deletedfromsql(1, n1) = xlSheet.Cells(q(1), 2)
deletedfromsql(2, n1) = xlSheet.Cells(q(1), 3)
deletedfromsql(3, n1) = xlSheet.Cells(q(1), 4)
End If
Next i
'End If
n = 0
Do
n = n + 1
If xlsheet2.Cells(n + 13, 1) > " " Then
ReDim Preserve rev(10, n)
ReDim Preserve part(n)
'part(n) = xlSheet.Cells(n + 13, 3) & "*" & xlSheet.Cells(n + 13, 1)
If xlsheet2.Cells(n + 13, > CDate(lastrevdate) Then
lastrevdate = xlsheet2.Cells(n + 13, 8-)
End If
For i = 1 To 10
rev(i, n) = xlsheet2.Cells(n + 13, i)
Next i
Else
Exit Do
End If
Loop
If engr = "" Then
engr = xlSheet.Cells(14, 2)
chcked = xlSheet.Cells(14, 3)
End If
Else
mbomflag = 0
revlev = 0
If engr = "" Then
engr = UCase$(InputBox("Enter Mechanical drafter's Initials:", "Enter Initials"))
'If engr = "" Then Exit Sub
chcked = UCase$(InputBox("Enter Checker's Initials:", "Enter Initials"))
'If chcked = "" Then Exit Sub
End If
End If
'Set xlBook = GetObject(path(2) & "vb\sql\ebomtemplate.xls")
Set xlBook = GetObject(Defaults.ApplicationPath & "\mbomTemplate.xls")
Set xlSheet = xlBook.Worksheets(1)
Set xlsheet2 = xlBook.Worksheets(2)
If revlev = 0 Then
xlsheet2.Cells(14, 8= Date
End If
'xlSheet.PageSetup.Zoom = 50
If UBound(rev, 2) > 0 Then
lastrevrow = UBound(rev, 2) + 13
For i = 14 To UBound(rev, 2) + 13
For j = 1 To 10
xlsheet2.Cells(i, j) = rev(j, i - 13)
Next j
Next i
Else
lastrevrow = 13
End If
'If uprev = 1 Then
' xlBook.Application.Visible = True
' xlBook.Parent.Windows(2).Visible = True
' xlBook.Parent.Windows(2).Activate
' xlSheet.Activate
'bFound = bringwindowtotop(hwnd)
'xlBook.Sheets(1).Select
'ActiveSheet.Visible = True
'xlBook.Application.DoubleClick
'Else
xlBook.Application.Visible = True
xlBook.Parent.Windows(1).Visible = True
xlBook.Parent.Windows(1).Activate
xlSheet.Activate
'DetectExcel
'bFound = bringwindowtotop(hwnd)
'End If
'DetectVB
'Found = apiShowWindow(hwnd, SW_SHOWMINIMIZED)
'DetectExcel
'Found = apiShowWindow(hwnd, SW_SHOWMAXIMIZED)
Me.Visible = False
Screen.MousePointer = vbDefault
'If uprev = 1 Then
' xlBook.NewWindow.Activate
' With xlBook.NewWindow
' .ActiveSheet = 2
' .Zoom = 50
' End With
'End If
'xlBook.Application.Visible = True
'xlBook.Parent.Windows(1).Visible = True
'xlSheet.Activate
'qs(1) = "03040609121314151617181920212223242526272829303132333435"
cs = UCase$(cs)
sos = UCase$(sos)
xlSheet.Cells(10, 2) = cs & Left$(sos, 5)
If Val(framestr(0, 0, 15)) < 8 Then qs(1) = "2" Else qs(1) = "4"
xlSheet.Cells(10, 3) = "-" & Mid$(sos, 6, 1) & Right$(sos, 1) & "B" & qs(1) & "004"
xlSheet.Cells(12, 2) = Right$(sos, 3)
xlSheet.Cells(10, 6) = framestr(0, 0, 3)
'xlSheet.Cells(12, 3) = "0"
'xlSheet.Cells(16, 2) = Date
'xlSheet.Cells(16, 3) = Date
xlSheet.Cells(10, 4) = framestr(0, 0, 658) 'sold to
xlSheet.Cells(11, 4) = framestr(0, 0, 657)
xlSheet.Cells(12, 4) = framestr(0, 0, 656)
xlSheet.Cells(14, 2) = engr
xlSheet.Cells(14, 3) = chcked
xlSheet.Cells(14, 4) = framestr(0, 0, 655) 'for
xlSheet.Cells(14, 6) = framestr(0, 0, 661) 'purchase order
xlSheet.Cells(15, 4) = framestr(0, 0, 654)
xlSheet.Cells(16, 4) = framestr(0, 0, 653)
xlcol = "L M N O P Q R S T U V W X Y Z AAABACADAEAFAGAHAIAJ"
qs(1) = "L12:" & Trim$(Mid$(xlcol, (nof + 1) * 2 - 1, 2)) & "16"
xlSheet.Cells.Range(qs(1)).Value = " "
For i = 1 To nof
xlSheet.Cells(19, i + 11) = i
Next i
For i = 1 To nof + 1
qs(1) = Trim$(Mid$(xlcol, i * 2 - 1, 2)) & "12:" & Trim$(Mid$(xlcol, i * 2 - 1, 2)) & "16"
With xlSheet.Cells.Range(qs(1)).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
Next i
qs(1) = Chr(76) & "12:" & Trim$(Mid$(xlcol, nof * 2 - 1, 2)) & "12"
With xlSheet.Cells.Range(qs(1)).Borders(xlTop)
'.LineStyle = xlContinuous
.Weight = xlMedium
End With
qs(1) = Chr(76) & "16:" & Trim$(Mid$(xlcol, nof * 2 - 1, 2)) & "16"
With xlSheet.Cells.Range(qs(1)).Borders(xlBottom)
'.LineStyle = xlContinuous
.Weight
I am aware VB 6 is outdated and not sure why they don't move to VB.NET. I would really appreciate if anyone can help. Thanks in advance :)
Your problem is nothing to do with VB6 being outdated. The problem is that this code is unrunnable. I can only make a guess that this is some hacked version based on the real running code. I will make some guesses based on approximately what this code should really look like. However, it would be a good idea to provide the actual code.
By "tabs", I take it you mean "worksheets". I am guessing that they are called "Sheet1" and "Sheet2". So basically, only "Sheet1" is actually getting re-populated. "Sheet2" remains as it previously looked.
I would suggest that you put a breakpoint on the line:
Set xlsheet2 = xlBook.Worksheets(2)
See whether xlsheet2.Cells(14,8) evaluates to the date you expect to see on that worksheet.
After stepping through this line, ensure that xlsheet2 actually points to the worksheet you expect it to. I would also put breakpoints on every line which reads or writes xlsheet2.Cells(x,y) evaluate it, and look at sheet2, ensuring that the value read or written back is correct.

Resources