VBA help sheet code

ottasight

New Member
Joined
Feb 15, 2009
Messages
47
hi, why doesn't this work........thanks


Private Sub testit()
Dim a As Integer
Dim x As Integer
a = 25
For x = 1 To 5
Range("ax").FormulaR1C1 = a
Next x
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Bieli
for some reason code didn't work

Hiker95
code is place in vb sheet code rather than module. it should print 25 in each cell a1:a5.........thanks for any help
 
Upvote 0
ottasight,


Sample worksheet before either of the two Worksheet_Calculate Events:


Excel Workbook
A
1
2
3
4
5
6
Sheet1





After your macro code (slightly changed), and (after a macro with one line of code):


Excel Workbook
A
125
225
325
425
525
6
Sheet1





You can only have one Worksheet_Calculate Event per worksheet.



Your looping code slightly changed:


Code:
Option Explicit
Private Sub Worksheet_Calculate()
' hiker95, 09/13/2011
' http://www.mrexcel.com/forum/showthread.php?t=578637
Dim a As Long
Dim x As Long
a = 25
For x = 1 To 5
  Range("A" & x) = a
Next x
End Sub




And, a macro with one line of code:


Code:
Option Explicit
Private Sub Worksheet_Calculate()
' hiker95, 09/13/2011
' http://www.mrexcel.com/forum/showthread.php?t=578637
Range("A1:A5") = 25
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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