Which Variable to use?

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Hi there,

On my last few threads I have been asking questions about how to best declare variables. After reading through the excellent content on C Pearsons website I now have a better understanding of how to declare a variable.

What it doesn't give me however is a list of what variables to use in certain situations. For example...

Text would be As String
Number would be As Intiger
True would be As Boolean

...does anyone have a list of what variables to use and when?

Andy
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Thanks, what variable should I use for this...

Code:
DeleteCode = Application.InputBox("Please enter the delete code")
 

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889

ADVERTISEMENT

Thanks! I'm going through and properly declaring all my variables, there are about 46,000 lines of code so expect a few questions over the next few days!

Cheers again,

Andy
 

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Okay next one...

Code:
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
        
    With OutMail
        .To = "" & DevelopmentAddress & ""
        .CC = ""
        .BCC = ""
        .Subject = "Connect: Gateway Error"
        .body = "Date: " & vbTab & vbTab & vbTab & Format(Now, "dd-mmmm-yyyy") & vbNewLine & _
        "Version Name: " & vbTab & "" & VersionName & "" & vbNewLine & _
        "Record ID: " & vbTab & vbTab & "" & RecordID & "" & vbNewLine & _
        "Connect Routine: " & vbTab & vbTab & "" & ConnectSubRoutine & ""
        .Send
    End With
    Set OutMail = Nothing
    Set OutApp = Nothing

OutMail and OutApp?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,066
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

Assuming you are late binding, declare them both as Object.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Dim OutApp As Object
Dim OutMail As Object
 

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Excellent, okay next...

Code:
ActiveRow = Worksheets("Status History").Range("B" & Range("B65536").End(xlUp).Offset(1, 0).Row & "").Row

String?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,397
Messages
5,595,925
Members
414,033
Latest member
torreyanderson

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
Top