473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Excel Macro: incrementing "Sheets"

I need to use Macro's in Excel and always the same changes to 31 Sheets. (31 days in the Month).
I'm trying to use a FOR loop but cannot get the correct format to have the sheet number to increment by 1 in each loop.
Below is a silly little Macro but indicates what my problem is.
I have tried inserting my variable intSheet in various ways including concatenation to no avail.
Any help would be greatly appreciated.
Thankyou
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 02 09 2006
'
Dim intCounter As Integer
Dim intSheet As Integer

For intCounter = 1 To 31

Range("C5").Select
ActiveCell.FormulaR1C1 = "hello"
Range("C6").Select
Sheets("Sheet1").Select 'I need this sheet to increment by 1 each loop
Range("C6").Select ' I tried various ways of using intSheet to replace "Sheet1"

intSheet = intSheet + 1

Next

End Sub
Sep 2 '06 #1
3 7234
Sheets("Sheet1").Select 'I need this sheet to increment by 1 each loop
Range("C6").Select ' I tried various ways of using intSheet to replace "Sheet1"


this is a much simplified version of your pilot script:


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/3/06 by dave ellis
'

'
Dim intSheet As Integer

For intSheet = 0 To 30
intSheet = intSheet + 1

Range("C5").FormulaR1C1 = "hello"
Range("C6").Select
Sheets(intSheet).Select 'I need this sheet to increment by 1 each loop
Range("C6").Select ' I tried various ways of using intSheet to replace "Sheet1"

Next intSheet
End Sub

voila!
Sep 4 '06 #2
a correction to the previous reply

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/3/06 by dave ellis
'

'
Dim intSheet As Integer

For intSheet = 1 To 31 ' restored your original idea here, and ...
'intSheet = intSheet + 1 ' notice, you need not literally increment your variable

Range("C5").FormulaR1C1 = "hello"
Range("C6").Select
Sheets(intSheet).Select 'I need this sheet to increment by 1 each loop
Range("C6").Select ' I tried various ways of using intSheet to replace "Sheet1"

Next intSheet
End Sub

sorry for the misstep, and finally, voila!
Sep 4 '06 #3
Hi Dave,
Thankyou very much! Works like a dream. Now I can use any macro and have it repeated 31 times :)
Sep 7 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
0
by: Ronald Snelgrove | last post by:
To All: I am a newbie to VB.net and am writing an application in VB.net in which I successfully create an Excel sheet, tabulate and format some data on a sheet titled "summarySheet". A...
0
by: Microsoft | last post by:
I have a porgram that opens an excel workbook and modifies some data, but almost randomly a box will pop up in the workbook telling me the file is now available and to hit ok or cancel. This...
0
by: Eric W | last post by:
I am converting an EXCEL VBA application to Visual Basic (2003). I am not having much luck finding how to convert statements containing references to things like ThisWorkbook.Sheets("sheetname")....
4
by: Eric W | last post by:
I am converting an EXCEL VBA application to Visual Basic (2003). I am not having much luck finding how to convert statements containing references to things like ThisWorkbook.Sheets("sheetname")....
2
by: sherifffruitfly | last post by:
Hi, I'm using an adaptation of excel-reading code that's all over the internet - I don't much like or understand it, but it has worked for me in the past.... beggars can't be choosers... : ...
0
by: =?Utf-8?B?TW9udGU=?= | last post by:
I am using VB.NET to open and read info from Excel spreadsheets using code similar to this: Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlBooks As Excel.Workbooks Dim...
5
by: cloh | last post by:
Hi all, I am using Access to grab some data from a database and plot a graph in Excel. When I do this, there is a message box in Excel that pop ups with an initialization error, that asks me to click...
1
by: dehboy | last post by:
Here's the deal. I'm trying to write an excel macro in VBA that will take a bunch of data and create a nice bubble chart out of it. First, it checks if the row I'm adding to the chart is the first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.