Sub Button4_Click()
Sheets(quot;Calculationsquot;).Select
Dim curdate As String
Dim predate As String
curdate = Range(quot;F18quot;).Value
predate = Range(quot;F17quot;).Value
Workbooks.Open Filename:= _
quot;S:\ New\New Business All.xlsquot;
Range(quot;C3quot;).Select
ActiveCell.FormulaR1C1 = quot;predatequot;
Range(quot;D3:G3quot;).Select
ActiveCell.FormulaR1C1 = quot;curdatequot;
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)Why not just use
Range(quot;C3quot;).Value = predate
etc....
You also do not specify which Sheet should be populated with these values
--
Kind Regards,
Will Rileyquot;PaulWquot; wrote:
gt; Sub Button4_Click()
gt;
gt; Sheets(quot;Calculationsquot;).Select
gt; Dim curdate As String
gt; Dim predate As String
gt; curdate = Range(quot;F18quot;).Value
gt; predate = Range(quot;F17quot;).Value
gt; Workbooks.Open Filename:= _
gt; quot;S:\ New\New Business All.xlsquot;
gt; Range(quot;C3quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;predatequot;
gt; Range(quot;D3:G3quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;curdatequot;
gt;
gt; This is the beginning part of a macro, if I have “ around predate and
gt; curdate they show as those words, when I don’t they get put as 0.
gt;
gt; Currently the values of these are April in F18 (curdate) and March in F17
gt; (predate)
gt;
Either declare them as dates
Dim curdate As Date
Dim predate As Date
or use the Text property
curdate = Range(quot;F18quot;).Text
predate = Range(quot;F17quot;).Text--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;PaulWquot; gt; wrote in message
...
gt; Sub Button4_Click()
gt;
gt; Sheets(quot;Calculationsquot;).Select
gt; Dim curdate As String
gt; Dim predate As String
gt; curdate = Range(quot;F18quot;).Value
gt; predate = Range(quot;F17quot;).Value
gt; Workbooks.Open Filename:= _
gt; quot;S:\ New\New Business All.xlsquot;
gt; Range(quot;C3quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;predatequot;
gt; Range(quot;D3:G3quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;curdatequot;
gt;
gt; This is the beginning part of a macro, if I have quot; around predate and
gt; curdate they show as those words, when I don't they get put as 0.
gt;
gt; Currently the values of these are April in F18 (curdate) and March in F17
gt; (predate)
gt;
Hi, I tried Range(quot;C3quot;).Value = predate
instead of
Range(quot;C3quot;).Select
ActiveCell.FormulaR1C1 = quot;predatequot;
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
quot;Calculation Sheetquot; 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.
quot;WillRquot; wrote:
gt; Why not just use
gt;
gt; Range(quot;C3quot;).Value = predate
gt;
gt; etc....
gt;
gt; You also do not specify which Sheet should be populated with these values
gt;
gt;
gt;
gt; --
gt; Kind Regards,
gt; Will Riley
gt;
gt;
gt; quot;PaulWquot; wrote:
gt;
gt; gt; Sub Button4_Click()
gt; gt;
gt; gt; Sheets(quot;Calculationsquot;).Select
gt; gt; Dim curdate As String
gt; gt; Dim predate As String
gt; gt; curdate = Range(quot;F18quot;).Value
gt; gt; predate = Range(quot;F17quot;).Value
gt; gt; Workbooks.Open Filename:= _
gt; gt; quot;S:\ New\New Business All.xlsquot;
gt; gt; Range(quot;C3quot;).Select
gt; gt; ActiveCell.FormulaR1C1 = quot;predatequot;
gt; gt; Range(quot;D3:G3quot;).Select
gt; gt; ActiveCell.FormulaR1C1 = quot;curdatequot;
gt; gt;
gt; gt; This is the beginning part of a macro, if I have “ around predate and
gt; gt; curdate they show as those words, when I don’t they get put as 0.
gt; gt;
gt; gt; Currently the values of these are April in F18 (curdate) and March in F17
gt; gt; (predate)
gt; gt;
- Sep 23 Tue 2008 20:46
VBA Code Errors
close
全站熱搜
留言列表
發表留言