need help compiling data via a macro

forgottenitall

New Member
Joined
Sep 28, 2011
Messages
4
Hi All,
This may seem ambititious but I have done it before (about 13 years ago) so I'm sure the functions are still there. I have multiple sheets in a workbook with the same name and an ascending number (e.g., "data 1" , "data 2", etc..) and I want to compile the information from specifics rows into one continuous list of information on another sheet. I vaguely recall writing a code that would use a counter to change a variable and then input htat variable in the sheet name so it could be activated. And then data could be chosen by cells and appended into a separate sheet.

Any guidance on any part of this would be greatly appreciated!

Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
See if this helps

Code:
Sub s()
Dim sName As String: sName = "Data"
Dim shName As String
Dim i As Integer
On Error Resume Next
For i = 1 To ActiveWorkbook.Sheets.Count
      shName = sName & CStr(i)
      If Not Sheets(shName) Is Nothing Then
            Sheets(shName).Select
      End If
Next i
On Error GoTo 0
End Sub
 
Upvote 0
Thanks for your help, craig.penny
I'm getting an error when it compiles at this line:
Dim sName As String: sName = "Data"
saying that's its a "Invalid Outside Procedure"

Also, what is the syntax for picking a row and column based on a counter number, too?

thanks again for helping me!
 
Upvote 0
I don't know if it'll make a difference but perhaps running it this way will work

Code:
Sub s()
Dim sName As String
sName = "Data"
Dim shName As String
Dim i As Integer
On Error Resume Next
For i = 1 To ActiveWorkbook.Sheets.Count
      shName = sName & CStr(i)
      If Not Sheets(shName) Is Nothing Then
            Sheets(shName).Select
      End If
Next i
On Error GoTo 0
End Sub

As for rows and columns it's just like matrix algebra where the cell reference is Cells(Row, Column) which is opposite of how it's often done using Range("B2") - ColumnRow. Anyways try this code

Code:
Sub CellSelection()
Dim RowCnt As Long
Dim ColCnt As Long
For RowCnt = 1 To 10
      For ColCnt = 1 To 10
            Cells(RowCnt, ColCnt).Select
      Next ColCnt
Next RowCnt
 End Sub

It will make a lot more sense if you have the code window open and press F8 repeatedly so that you can see which line of code is producing the on-screen results.

By the way, I like your user name. I'm getting pretty old and forgetting stuff faster than I'm learning new stuff! :laugh:
 
Upvote 0
Thank you so much, craig.penny!
This little bit of code jogged my memory enough for me to work out the kinks in my entire macro! Looks like I haven't "forgottenitall" afterall!
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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