VBA Code Errors

G

Guest

Sub Button4_Click()

Sheets("Calculations").Select
Dim curdate As String
Dim predate As String
curdate = Range("F18").Value
predate = Range("F17").Value
Workbooks.Open Filename:= _
"S:\ New\New Business All.xls"
Range("C3").Select
ActiveCell.FormulaR1C1 = "predate"
Range("D3:G3").Select
ActiveCell.FormulaR1C1 = "curdate"

This is the beginning part of a macro, if I have “ around predate and
curdate they show as those words, when I don’t they get put as 0.

Currently the values of these are April in F18 (curdate) and March in F17
(predate)
 
G

Guest

Why not just use

Range("C3").Value = predate

etc....

You also do not specify which Sheet should be populated with these values
 
B

Bob Phillips

Either declare them as dates

Dim curdate As Date
Dim predate As Date

or use the Text property

curdate = Range("F18").Text
predate = Range("F17").Text


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
G

Guest

Hi, I tried Range("C3").Value = predate
instead of

Range("C3").Select
ActiveCell.FormulaR1C1 = "predate"

And still end up with blank cells. I tried putting text instead of value
when assigning the variables as well, but that didn't help...

Sorry if i'm being a bit thick, i've only been using VBA a few days and just
about everything I do on it is recording macros, and copy and pasting it with
bits I find on this forum, which is where i'm getting all the variable stuff.

This macro is to update a spreadsheet which shows figures for the current
month. To make it easier to use I didn't want any links to outside sheets, so
do everything by copying and pasting to this sheet. The Macro is on a
"Calculation Sheet" which switches to a Calculation Tab, gathers the
information it needs, opens New Business All and pastes it in. The months
March and April are column headers compairing this months figures to last
months.

New Business All only has 1 sheet, and this is the sheet that wants
populating with this information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top