+ Reply to Thread
Results 1 to 3 of 3

The table that i generate with VBA didn't match with my data sheet

  1. #1
    Registered User
    Join Date
    02-18-2023
    Location
    Kuala Tanjung, Indonesia
    MS-Off Ver
    2019
    Posts
    17

    The table that i generate with VBA didn't match with my data sheet

    Hi,

    I face a problem with the output of my VBA. The output suppose to be the same with my excel sheet, but the outcome was not what i expected.

    The outcome is suppose to be like this in email.

    material.PNG

    But my the outcome is like this

    Material 2.PNG

    And here is my code

    [/HTML]Sub Email()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strBody As String
    Dim rng As Range
    Dim cell As Range
    Dim tbl As String
    Dim i As Integer

    Set rng = Nothing
    On Error Resume Next
    Set rng = Sheets("AUTO-BUY").Range("A4:F412").SpecialCells(xlCellTypeVisible)

    If rng Is Nothing Then
    MsgBox "No data to send to email email."
    Exit Sub
    End If

    tbl = "<table style='border-collapse: collapse; border: 1px solid black;'>"
    tbl = tbl & "<tr><th style='border: 1px solid black; padding: 5px;'>Nama Part</th><th style='border: 1px solid black; padding: 5px;'>Spesifikasi</th><th style='border: 1px solid black; padding: 5px;'>Nomor Material Code</th><th style='border: 1px solid black; padding: 5px;'>Status</th><th style='border: 1px solid black; padding: 5px;'>Jumlah yang Dibeli</th><th style='border: 1px solid black; padding: 5px;'>Remarks</th></tr>"

    For Each cell In rng
    If cell.Value <> "" Then
    If i Mod 2 = 0 Then
    tbl = tbl & "<tr style='background-color: #F2F2F2;'>"
    Else
    tbl = tbl & "<td>"
    End If
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 0).Value & "</td>"
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 1).Value & "</td>"
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 2).Value & "</td>"
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 3).Value & "</td>"
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 4).Value & "</td>"
    tbl = tbl & "<td style='border: 1px solid black; padding: 5px;'>" & cell.Offset(0, 5).Value & "</td>"
    tbl = tbl & "</td>"
    i = i + 1
    End If
    Next cell
    tbl = tbl & "</table>"

    If i = 0 Then
    MsgBox "No data to send to email."
    Exit Sub
    End If

    strBody = "Daftar Barang dengan Stok Kuning dan Merah: " & vbCrLf & vbCrLf
    strBody = strBody & tbl

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    .To = Range("I3").Value
    .CC = ""
    .BCC = ""
    .Subject = "Daftar Barang dengan Stok Kuning dan Merah"
    .HTMLBody = strBody
    .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    End Sub

    Which line of my code is wrong?

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: The table that i generate with VBA didn't match with my data sheet

    Try it
    Please Login or Register  to view this content.
    Artik

  3. #3
    Registered User
    Join Date
    02-18-2023
    Location
    Kuala Tanjung, Indonesia
    MS-Off Ver
    2019
    Posts
    17

    Re: The table that i generate with VBA didn't match with my data sheet

    Thanks
    this work perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Power Query - Expression Error: The Key didn't match any rows in the table
    By Baltimorejack68 in forum Excel General
    Replies: 7
    Last Post: 10-18-2019, 04:24 PM
  2. Replies: 9
    Last Post: 04-15-2014, 08:12 PM
  3. [SOLVED] Generate List of Records that Match Multiple Criteria from Data Table
    By trandle in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-10-2014, 04:43 PM
  4. [SOLVED] Delete the entire row if condition didn't match
    By sunheroj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2012, 04:08 PM
  5. [SOLVED] Match Formula Didn't Return Value after 11th Column
    By suriawati in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-07-2012, 11:52 PM
  6. Replies: 5
    Last Post: 01-06-2012, 08:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1