Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default macro to return value of worksheets

hi. how do i make a macro that returns the value of the cell next to the word
"total" from all worksheets which are listed in column A? i got to make the
macro that lists all worksheets in that workbooks into a summary worksheet.
Now i would like to find the value of the total amount in each worksheet and
return it to the next column of their corresponding sheet name lists? the
first macro is like this:

Sub auto_open()
Sheets("summary").Activate
x = 1
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Cells(x, 1).Value = ws.Name
x = x + 1
Next ws
Cells(1, 2).Value = x - 1
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default macro to return value of worksheets

Assume that the value is to the right of Total and that
"Total" is proper case, only appears once in each sheet
and could be located anywhere on the sheet.

Sub getData()
Dim ws As Range
Dim c As Range
SName = ActiveSheet.Name
lr = Cells(Rows.Count, 1).End(xlUp).Row
For Each ws In Sheets(SName).Range("A2:A" & lr)
If Not ws Is Nothing Then
fAddr = ws.Address
fName = ws.Value
Set c = Worksheets(fName).Cells.Find("Total", LookIn:=xlValues)
If Not c Is Nothing Then
c.Offset(0, 1).Copy Sheets(SName).Range(fAddr).Offset(0, 1)
End If
End If
Next
End Sub

"Chris" wrote:

hi. how do i make a macro that returns the value of the cell next to the word
"total" from all worksheets which are listed in column A? i got to make the
macro that lists all worksheets in that workbooks into a summary worksheet.
Now i would like to find the value of the total amount in each worksheet and
return it to the next column of their corresponding sheet name lists? the
first macro is like this:

Sub auto_open()
Sheets("summary").Activate
x = 1
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Cells(x, 1).Value = ws.Name
x = x + 1
Next ws
Cells(1, 2).Value = x - 1
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default macro to return value of worksheets

i tried the macro, and it returns a #ref! error on the cell.... yup, the
value is to the right of the word "total, and it only appears once in each
sheet and could be located anywhere in each sheet....

"JLGWhiz" wrote:

Assume that the value is to the right of Total and that
"Total" is proper case, only appears once in each sheet
and could be located anywhere on the sheet.

Sub getData()
Dim ws As Range
Dim c As Range
SName = ActiveSheet.Name
lr = Cells(Rows.Count, 1).End(xlUp).Row
For Each ws In Sheets(SName).Range("A2:A" & lr)
If Not ws Is Nothing Then
fAddr = ws.Address
fName = ws.Value
Set c = Worksheets(fName).Cells.Find("Total", LookIn:=xlValues)
If Not c Is Nothing Then
c.Offset(0, 1).Copy Sheets(SName).Range(fAddr).Offset(0, 1)
End If
End If
Next
End Sub

"Chris" wrote:

hi. how do i make a macro that returns the value of the cell next to the word
"total" from all worksheets which are listed in column A? i got to make the
macro that lists all worksheets in that workbooks into a summary worksheet.
Now i would like to find the value of the total amount in each worksheet and
return it to the next column of their corresponding sheet name lists? the
first macro is like this:

Sub auto_open()
Sheets("summary").Activate
x = 1
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Cells(x, 1).Value = ws.Name
x = x + 1
Next ws
Cells(1, 2).Value = x - 1
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
return value from range of worksheets aglen Excel Worksheet Functions 2 December 3rd 09 01:37 AM
Compare 2 Worksheets and return differences in a third. TheBigStig Excel Worksheet Functions 4 November 1st 07 09:06 AM
How can i compare particular columns of two worksheets and get a return henson1182 Excel Programming 2 May 9th 07 04:29 PM
matching two worksheets and return to different value dan Excel Worksheet Functions 2 October 23rd 06 11:18 PM
Function to Return another Worksheets Name Dawg House Inc Excel Worksheet Functions 7 March 22nd 05 07:10 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"