VBA set variable from cell value

Hector

New Member
Joined
Jan 13, 2003
Messages
16
It seems like this ought to be simple, but I can't figure out the correct syntax.

I have a worksheet (Sheet1) with a value of 1234 in cell F12. It is formatted as a number with 0 decimal places. I am trying to copy that value of 1234 into a variable. Here is my routine:

Sub SetVarFromCell()
Dim FTW As Long
Worksheets("Sheet1").Activate
FTW = Cells(12, "F").Value
End Sub


This routine runs without error, but FTW has a value of "0", rather than "1234" which is what it is supposed to have. I have also tried the statement:
FTW = Range("F12").Value and the result is the same -- "0" instead of "1234".

Is there a way to assign the value of the cell (1234) to the variable FTW?

Thanks,
Hector
 
Hello :)

I found this topic and tried to apply it to the following piece of code, that automates e-mail sending:

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.to = Worksheets("SETUP").Cells(4, "C").Value
.CC = Worksheets("SETUP").Cells(5, "C").Value
.BCC = ""
.Subject = Worksheets("SETUP").Cells(6, "C").Value
.Body = "My text to receipients"
.Attachments.Add Destwb.FullName
'.Send
.Display
End With
On Error GoTo 0
.Close savechanges:=False
End With

Simply speaking I have a worksheet called SETUP in which I want to configure e-mail addresses of all receipients without allowing user to touch VBA.
For some reason I get no values assigned to OutMail.to , .cc & .Subject.

.Send doesn't work (since .to has no value, so I used .display for tests).
When I do .display it shows no value.

Would anyone have any idea what could have I missed here?

I ran out of ideas...

Thank you for your help,
mesje

Mesje,

Try doing this...

Dim MAILTO As String
Dim MAILCC As String
Dim MAILSBJ As String

'Set email address
Worksheets("Setup").Activate
MAILTO = Cells(4, "C").Value

MAILCC = Cells(5, "C").Value
MAILSBJ = Cells(6, "C").Value

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.to = MAILTO
.CC = MAILCC
.BCC = ""
.Subject = MAILSBJ
.Body = "My text to receipients"
.Attachments.Add Destwb.FullName
'.Send
.Display
End With
On Error GoTo 0
.Close savechanges:=False
End With
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,784
Messages
6,121,539
Members
449,038
Latest member
Guest1337

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