Offset function-active cell help

neveu

Board Regular
Joined
Jan 27, 2009
Messages
225
Hello,
i'm using the for each stamenent and offset for a macro to send via email different data ranges to vendors.

i am having trouble with the offset function:
after i extract the unique emails adress and the range from where they start to where they end (see the offset lines in code)
i would like to test if the coresponding value in column T is either 2template or 1template.

based on this i will send a different message.
i am using the offset function to test that in the code with an if but it doesn't seem to work. what am i missing?

i would really need your help to reach to a solution.

thank you in advance



Uploaded with ImageShack.us
Code:
Sub SendEmailRange()
With Application
     .ScreenUpdating = False
     .DisplayAlerts = False
     .EnableEvents = False
     
End With
Dim cell As Range
Dim BankRng As Range
Dim HeaderBank As Range
Dim BankData As Range
Dim sumRng As Range
Dim LegalName As Range
Dim counter As Integer
Dim Outlook As Object  ' Outlook.Application
Dim OutlookMsg As Object  'Outlook.MailItem
Set Outlook = CreateObject("Outlook.Application")
On Error Resume Next
 With ActiveWorkbook.Sheets("Debit balances")
  
 counter = .Cells(Rows.Count, "L").End(xlUp).Row
  
 End With
'Clear range & filter the unique values
 Range("O:T").ClearContents
 Range("M1:M" & counter).AdvancedFilter xlFilterCopy, Range("O1:O" & counter), Range("O1"), Unique:=True
 
 LR_negative = Range("O" & Rows.Count).End(xlUp).Row
 LR_all = Range("D" & Rows.Count).End(xlUp).Row
'retrieves the coresponding template for each email adress
For p = 2 To LR_negative
   If Range("O" & p) <> "" Then
    Range("T" & p) = Application.VLookup(Cells(p, 15), Range("M2:N" & LR_all), 2, 0)
    
    End If
Next p
 
'Delete the top row
 Range("O1:T1").ClearContents
 
'add the "count" correspondent values for each cell that contains an email address
 For Each cell In Columns("O").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" Then
 
        Set sumRng = Range("P1:P" & Cells(cell.Row, "P").Row - 1) 'change K1 to K2 if you have header row
 
        cell.Offset(0, 1).Value = Application.WorksheetFunction.CountIf(Range("M1:M" & counter), Cells(cell.Row, "O").Value)
        cell.Offset(0, 2).Value = Application.WorksheetFunction.Sum(sumRng) + 2
        cell.Offset(0, 3).Value = Cells(cell.Row, "P").Value + (Cells(cell.Row, "Q").Value - 1)
        cell.Offset(0, 4).Value = Application.WorksheetFunction.Sum(Range("K" & Cells(cell.Row, "Q").Value, "K" & Cells(cell.Row, "R").Value))
        
        
        Set BankRng = Range(("A" & (Cells(cell.Row, "Q").Value)), ("K" & Cells(cell.Row, "R").Value))
        Set HeaderBank = Range("A1:K1")
 
        Set BankData = Union(HeaderBank, BankRng)
 
 'Set LegalName = Range(("B" & (Cells(cell.Row, "Q").Value)))
 
'Create the email message for each line from column A
        If Cells.Offset(0, 5).Value = "1tempalte" Then
            Set OutlookMsg = Outlook.CreateItem(olMailItem)
           With OutlookMsg
            ' set basic params
            .Subject = "1tempalte"
            .HTMLBody = "Sehr geehrte Damen und Herren, , " & "<br><br>" & _
                "  balance is :" & Cells(cell.Row, "S").Value & ". Da wir auch in der nächsten Zeit keine Rechnungen von Ihnen erwarten, " & _"<br><br>"                 
            .To = cell.Value
            .display
            End With
 
     Else
 
            If Cells(0, 5).text = "2template" Then
            With OutlookMsg
    ' set basic params
            .Subject = "2template "
            .HTMLBody = "Sehr geehrte Damen und Herren, , " & "<br><br>" & _
                "auf unserer ;   balance is :" & Cells(cell.Row, "S").Value &  _
                "asdfsdfs" & "<br>"
                .To = cell.Value
                .display
    
        
            End With
        End If
  End If
 End If
Next cell
End Sub
like to test if the value from
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Looks like a typo you are using Cells instead of cell.
Change
Code:
If Cells(0, 5).text = "2template" Then
If Cells.Offset(0, 5).Value = "1tempalte" Then
to
Code:
If cell.Offset(0, 5).Value = "2template" Then
If cell.Offset(0, 5).Value = "1tempalte" Then
 
Upvote 0
thanks a milion!

you really saved me.
it seems i was to tired last night to notice that.

thank you very much
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top