WHAT DOES THE "i" in WS.RANGE MEAN?

JuicyMusic

Board Regular
Joined
Jun 13, 2020
Messages
210
Office Version
  1. 365
Platform
  1. Windows
Hello again, I'm not receiving any attention to my first post so I am asking the 3 questions I have separately. I've looked all over the Google but I may not be writing the correct search phrase.

Can someone please explain to me what the "i" in the following line of code means.

Here is the line of code that I am referring to:
Instrument1 = Instrument1 & ws.Range("A" &i).Value & ","
counter1 - counter1 + 1
End If

Thank you so much!
Juicy
 

Attachments

  • MR EXCEL_extend to 3 columns.PNG
    MR EXCEL_extend to 3 columns.PNG
    20.8 KB · Views: 14

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You need to look at the lines above the typed one you posted but basically the i is a variable based on the row number.
The line you should be looking at is
VBA Code:
For i  = 2 to lr
where lr is the last row with data's row number.

Btw if you are posting code it is better to paste the actual code in the thread and wrap it in code tags rather than post an image.
 
Upvote 0
Btw if you are posting code it is better to paste the actual code in the thread and wrap it in code tags rather than post an image.
I see that you made another post today with an image like you did here, and you mentioned that due to company policy you are unable to download anything.
Please note that you are not required to download any software to copy/paste your VBA code here.
Simply select all your code and click-copy (CTRL+C) and then paste it in the reply box (CTRL+V).
If you then select the code in the reply, and click on the "VBA" icon in the reply editor menu bar, it will format your code nicely like Mark's, which makes it easier for us to read (and copy, if necessary).
 
Upvote 0
Joe4, for some reason the icon bar in the reply window was greyed out yesterday but this morning it is slightly green for me.
Thanks for the clear instructions. Now I won't violate any rules and I can let you see the complete code.

Would you be able to assist me with further? I pasted a portion of a prior post that I titled "ADJUSTING RANGE FROM COLUMN A THRU C...(NOT JUST COLUMN A)" down below for you to see.
I've also attached an image of my spreadsheet. Columns A, B, C and L are the focus.

Here is what this code does:
1) Generates 2 different type of emails based on two texts in column L: "Expired" and "Expiring Soon"
2) It brings the data (insurance company name) from column A of the spreadsheet onto the body of the email. One email for all the rows that show "Expired", and another email for all the rows that show "Expiring Soon".

I NEED THE DATA THAT SHOWS UP ON THE EMAIL BODY TO BE FROM COLUMN A, B, AND C OF EACH ROW. WHICH WOULD BE THE INSURANCE CO. NAME (A), THE TYPE OF INSURANCE COVERAGE (B), AND THE ACCOUNT NUMBER (D), NOT JUST COLUMN A.



VBA Code:
Private Sub Workbook_Open()
Dim Instrument1 As String
Dim Instrument2 As String

Dim ws As Worksheet
Dim Status As String
Set ws = Sheets("Renewal Log")
lr = ws.Range("A" & Rows.Count).End(xlUp).Row
' MsgBox "This code ran at Excel start!"
' On Error Resume Next
' If Target.Cells.Count > 1 Then Exit Sub
counter1 = 0
counter2 = 0
On Error Resume Next
For i = 2 To lr
  Status = ws.Range("L" & i).Value
    If Status = "Expiring Soon" Then
Instrument1 = Instrument1 & ws.Range("A" & i).Value & ", "
counter1 = counter1 + 1
End If
If Status = "Expired" Then
Instrument2 = Instrument2 & ws.Range("A" & i).Value & ", "
counter2 = counter2 + 1
End If
Next i
If counter1 > 0 And counter1 = 1 Then Mail_Expiring_Soon_Outlook Left(Instrument1, Len(Instrument1) - 2)
If counter1 > 0 And counter1 > 1 Then Mail_Expiring_Soon_Outlook Left(Instrument1, Len(Instrument1) - 1)
If counter2 > 0 And counter2 = 1 Then Mail_Expired_Outlook Left(Instrument2, Len(Instrument2) - 2)
If counter2 > 0 And counter2 > 1 Then Mail_Expired_Outlook Left(Instrument2, Len(Instrument2) - 1)

End Sub
Sub Mail_Expiring_Soon_Outlook(Instrument1 As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Attention" & vbNewLine & vbNewLine & _
"The " & Instrument1 & " renewal is due soon." & vbNewLine & vbNewLine & _
"Please arrange for review or payment."
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Renewal date is approaching"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Sub Mail_Expired_Outlook(Instrument2 As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Warning!" & vbNewLine & vbNewLine & _
"The " & Instrument2 & " Registration/Coverage/License is expired." & vbNewLine & vbNewLine & _
"Please arrange for review or payment."
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Warning! Registration/Coverage/License is Expired"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub






Thank you so much! Juicy,
 

Attachments

  • Expiration worksheet.PNG
    Expiration worksheet.PNG
    37.7 KB · Views: 5
Upvote 0
Joe4, If you are willing to help me with this, is it possible for your to respond to my on my other post? That way I can click "SOLVED" on the correct post.
Let me know. Thanks!
Juicy
 
Upvote 0
Joe4, If you are willing to help me with this, is it possible for your to respond to my on my other post? That way I can click "SOLVED" on the correct post.
Let me know. Thanks!
Yes, you should keep the posts separate, since you already posted that question over there.

I was just responding as a Moderator, clarifying how to use certain tools on this forum.
Unfortunately, I do very little integration with email. As matter as fact, my company doesn't allow it, so I wouldn't be able to test anything out. So that is why I have not responded.
 
Upvote 0
Joe4, you are so excellent and I appreciate your time. I'll just wait and see. Thank you!!
Juicy,
 
Upvote 0
Joe4, Is there anywhere to start my post over from scratch? Or just wait for a Guru to find me?
 
Upvote 0
for some reason the icon bar in the reply window was greyed out yesterday but this morning it is slightly green for me.
If the Icon bar is greyed out again click the
1607629313890.png
symbol, it toggles the BB Code on and off.

Or just wait for a Guru to find me?
Reply with the word BUMP which will bring you post to the top of the questions (please don't do this more than once in 24 hours).
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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